Calculate total time based on column in Tableau - dashboard

I have a table like below:
From Date
Issue Id
Issue Id (group)
Status
Till Date
19-07-2021 17:21
4
4
Approved
19-07-2021 17:23
19-07-2021 17:23
4
4
In Progress
19-07-2021 17:23
19-07-2021 17:23
4
4
In Review
19-07-2021 17:25
19-07-2021 17:25
4
4
In Progress
19-07-2021 18:56
19-07-2021 18:56
4
4
In Review
20-07-2021 08:47
20-07-2021 08:47
4
4
Resolved
20-07-2021 14:45
20-07-2021 14:45
4
4
Closed
12-07-2021 10:49
4
4
Open
19-07-2021 17:21
27-04-2016 09:07
3
3
Open
10-01-2017 08:40
10-01-2017 08:40
3
3
Closed
10-01-2017 08:40
3
3
Resolved
10-01-2017 08:40
I need to do the following things:
For Issue Id 4 find the total time in hours or minutes or seconds or days for a particular type of status. For e.g There are 2 In Review rows. So the total time between From Date to Till date will be 17:23 (19-07) till 8:47(20-07).
calculate total time a issue is in between closed and In Review (here Till date for closed issues is unfortunately null).
Basically I am trying to create a dashboard where for each issue i'd i would like to see for how long was a issue "In Review" or "In Progress" before it was closed. So the dashboard will have "Issue Id" in the X axis and "Total Time for Review" or "Total Time for Progress" in the Y axis. For e.g Issue 4 was in a total of 1:31:01 Hours in the "In Progress" state (17:23 to 17:23 on 19th July and 17:25 to 18:56 on 19th July).
I am trying this:
IF [STATUS] = 'In progress' and [STATUS] = 'Closed'
THEN
DATEDIFF('day',[Date Create],[Till Date])
END but it says tables can only be aggregated and using Count function only.
Can someone please help? How can we create a calculated field for the above scenarios.

Think of your IF statements being applied to each row, you cannot have a status that is both in progress and closed.
I would arrange the text table like this:
Columns: Status
Rows: Issue ID (group) | Issue ID
Text Mark: Calculated Field (Named something like Total Time).
That will group all of the statuses together. You can change the aliases of the status if you want to say "Total Time for ..."
Then your calculated field would be:
DATEDIFF("day", [From Date], [Till Date])
And make sure you drag the pill over it is summing it. That will collapse everything at the status level, and then total the days.

Related

Power Query - Merge tables - Sum values with conditions

I'm new to Power Query and I can't figure out how to do the following:
I have two tables
"REQUESTED"
Date
ReqNumber
Client
SKU
ReqQuantity
Jan-01
Z10
1
A
2
Feb-05
Z11
1
A
3
"SENT"
Date
Client
SKU
Quantity
Jan-15
1
A
1
Feb-02
1
A
3
Mar-10
1
A
5
What I want to achieve is that I want to merfe the tables and allow me to filter by date, showing the corresponding amount requested/sent
For Example:
If I filter dates between Jan-01 / Jan - 31
I should get the following:
"REQUESTED - SENT"
Date
ReqNumber
Client
SKU
ReqQuantity
SentQuantity
Jan-01
Z10
1
A
2
1
If I filter dates between Jan-01 / Feb - 28
I should get the following:
"REQUESTED - SENT"
Date
ReqNumber
Client
SKU
ReqQuantity
SentQuantity
Jan-01
Z10
1
A
2
2
Feb-05
Z11
1
A
3
2
If I filter dates between Jan-01 / Mar- 15
I should get the following:
"REQUESTED - SENT"
Date
ReqNumber
Client
SKU
ReqQuantity
SentQuantity
Jan-01
Z10
1
A
2
2
Feb-05
Z11
1
A
3
3
Is this posiible in Power Query?
Thanks!
I believe your question is a simple one that might get passed over because it is simple.
Two tables "Sent" "Requested"...
Merge is under the Home tab.
Set "Requested" as Left and "Sent" as right. Select date for both.
In the Sent column click on the expand icon.

How to complete report derived from another query with zeros or nulls

So, I'm really having a hard time with a report.
I need a report grouped by year. For example, we want to show how many cars are sold per year. So, the report has a column Year, the type/model of the car, and the quantity. However, I also want to show a row with null/zero value, so even when no car of a specific type was sold, I want it to show the row, but with 0.
The problem is, this query is based on a lot of views, which shows each transaction. So, my actual query works fine except it doesn't show a type when none of that type was sold in a year.
When I pivot this report using Oracle APEX, it almost works. It shows all the types, but if I filter per year, then they are gone.
I have all the years I need, but I don't have the data for that year. I take all the data from multiple views with the specifics of the sales. Some of the models/types were not sold in some years, so when I query the report, it doesn't show up, which is expected. For example:
What I get is
//YEAR - MODEL - QUANTITY //
2018 - MODEL 1 - 300
2018 - MODEL 2 - 12
2017 - MODEL 1 - 12
2017 - MODEL 2 - 33
2017 - MODEL 3 - 22
What I want
//YEAR - MODEL - QUANTITY //
2018 - MODEL 1 - 300
2018 - MODEL 2 - 12
2018 - MODEL 3 - 0
2017 - MODEL 1 - 12
2017 - MODEL 2 - 33
2017 - MODEL 3 - 22
Any ideas?
You can conjure rows, and outer join to them.
with years as (
select add_months(date '1980-1-1', (rownum-1)*12) dt
from dual
connect by level < 5
)
select y.dt, count(e.hiredate)
from scott.emp e
right outer join years y
on y.dt = trunc(e.hiredate,'yy')
group by y.dt
DT COUNT(E.HIREDATE)
------------------- -----------------
01-01-1982 00:00:00 1
01-01-1983 00:00:00 0
01-01-1981 00:00:00 10
01-01-1980 00:00:00 1

Oracle SQL - Grouping multiple medical claims into one event

I'm trying to group multiple medical claims into one event, or inpatient stay. To keep this simple, let's say I have a patient who goes to the hospital on 1/1/2017, is released on 1/5/2017, and is transferred to another hospital on that same day, and is released from that other hospital on 1/10/2017.
So I have two claims, one with an admit date of 1/1/2017 and discharge date of 1/5/2017, and the other claim has an admit date of 1/5/2017 and discharge date of 1/10/2017. Because one starts right after the other, it is considered one inpatient stay.
In Oracle, I would like to combine that into one line, with an admit date of 1/1/2017, and a discharge date of 1/10/2017, based on the fact that the one claim has a discharge date of 1/5/2017, and the second claim has an admit date on that same date.
Any help on which direction to go into would be greatly appreciated.
UPDATE: Please see the sample data below:
CLAIM_ID MEME_RECORD_NO ADMIT_DATE DISCHARGE_DATE
1 127300 1/3/2017 1/11/2017
2 127300 1/12/2017 1/20/2017
3 180100 1/3/2017 1/6/2017
4 180100 1/6/2017 1/20/2017
5 265700 1/2/2017 1/5/2017
6 265700 1/5/2017 1/17/2017
7 300000 2/1/2017 2/5/2017
8 300000 2/5/2017 2/9/2017
9 300000 2/9/2017 2/12/2017
CLAIM_ID 1 and 2 are separate events, since the ADMIT_DATE for CLAIM_ID 2 is greater than the discharge date for CLAIM_ID 1 (even though they're the same patient), CLAIM_ID 3 and CLAIM_ID 4 combined is one event, since the discharge date for CLAIM_ID 3 is the same as the ADMIT_DATE for CLAIM_ID 4, and the scenario repeats itself for CLAIM_ID's 5 and 6. For CLAIM_ID'S 7, 8 and 9, this is also one event, so all 3 would be combined. In addition to actually grouping them, I would also like to number the rows with an EVENT_ID field
Assuming the above were a table, and I queried it, the output should be 5 events. The final product should look like this:
EVENT_ID MEME_RECORD_NO ADMIT_DATE DISCHARGE_DATE
1 127300 1/3/2017 1/11/2017
2 127300 1/12/2017 1/20/2017
3 180100 1/3/2017 1/20/2017
4 265700 1/2/2017 1/17/2017
5 300000 2/1/2017 2/12/2017
I really appreciate any help on this.

12 month rolling data from earliest invoice date - Hadoop

Seeking help with the following problem statement.
I/P Data Set:
customer id invoice date item id invoice amount Comment
1 10-Jan-2014 1 10 Start of 12 month window - 10th Jan 2014 to 10th Jan 2015
1 20-Jan-2014 2 20 Falls within 12 month window
1 21-Aug-2014 1 10 Falls within 12 month window
1 31-Dec-2014 1 10 Falls within 12 month window
1 20-Feb-2015 1 10 Start of new 12 month window as this is post 10th Jan 2015
1 30-Mar-2016 1 10 Start of new 12 month window as this is post 20th Feb 2016
Desired o/p
customer id invoice date item id invoice amount window sum(amount where item id = 1)
1 10-Jan-2014 1 10 1 10
1 20-Jan-2014 2 20 1 0
1 21-Aug-2014 1 10 1 20
1 31-Dec-2014 1 10 1 30
1 20-Feb-2015 1 10 2 10
1 30-Mar-2016 1 10 3 10
I tried using the following query in Hive to achieve the above output but the challenge is in resetting the next window once we have crossed the 12 month mark. (Please refer to rows 5 and 6 in the input data set). The need is for these records to be considered as start of a new window.
Following Query Used:
SELECT SUM(if(item_id = 1, invoice_amount, 0)) OVER (
PARTITION BY customer_id
ORDER BY invoice_date ASC
RANGE BETWEEN 31556926 PRECEDING AND CURRENT ROW
) FROM INVOICE_DETAILS;`

calculate the time difference for same column in Spotfire

I am a beginner for Spotfire. I have a problem about the difference calculation for the some column value. A sample table could be like this:
id timestamp state
1 7/1/2016 12:00:01 AM 1
2 7/1/2016 12:00:03 AM 0
3 7/1/2016 12:00:04 AM 1
4 7/1/2016 12:00:06 AM 0
5 7/1/2016 12:00:09 AM 1
6 7/1/2016 12:00:10 AM 0
7 7/1/2016 12:00:12 AM 1
I want to calculate the time difference for the timestamp when the state is 1,
the final table I want to have is:
id timestamp state time_diffence
3 7/1/2016 12:00:04 AM 1 3
5 7/1/2016 12:00:09 AM 1 5
7 7/1/2016 12:00:12 AM 1 3
it seems that I should identify an expression for the calculation, but I have not idea for the calculation just for one parameter :(. somebody could help me ?
still one more small question: what if the timestamp column value is just number value, how can i calculate the difference, is there any related function like DateDiff() here? for example:
id times state
1 12 1
2 7 0
3 10 1
4 11 0
5 6 1
6 9 0
7 7 1
the result could be :
id times state diffence
3 10 1 -2
5 6 1 -4
7 7 1 1
after running the code: i have the error as below:
for the row if it has the same time stamp as the last previous row, the difference will keep same as before, but actually the difference for the rows which have same time stamp would be as 0
thanks for your help :)
Assuming your data is sorted in ascending order by [timestamp] before you import it, you can partition using the Previous function with Over where the [state]=1.
Insert a calculated column with this expression:
If([state]=1,DateDiff("ss",Min([timestamp]) OVER (Previous([timestamp])),[timestamp]))
You will see it populated in your table like the below:
Then if you ONLY want to see the rows that have the difference you mentioned, on your table you can...
Right Click > Properties > Data > Limit data using expression >
And insert the expression: [time_difference] > 1
This will result in this table:

Resources