Forum Discussion
Calculate Difference between 2 rows based on another column filter
- 4 years ago
Hi,
This calculated column formula works
=if(CALCULATE(MAX(Data[Dates]),FILTER(Data,Data[serialid]=EARLIER(Data[serialid])))=Data[Dates],ABS(Data[GenHours]-LOOKUPVALUE(Data[GenHours],Data[Dates],CALCULATE(max(Data[Dates]),FILTER(Data,Data[serialid]=EARLIER(Data[serialid])&&Data[Dates]<EARLIER(Data[Dates]))),Data[serialid],Data[serialid])),BLANK())Hope this helps.
| Data | ||||
| descript | inci_id | timestamp | unitcode | |
| Dispatched | 2019365004 | 12/31/2019 00:26:00 | R97 | |
| En-Route | 2019365004 | 12/31/2019 00:27:00 | R97 | |
| Dispatched | 2019365007 | 12/31/2019 00:34:00 | LD97 | |
| Arrived | 2019365004 | 12/31/2019 00:34:00 | R97 | |
| En-Route | 2019365007 | 12/31/2019 00:35:00 | LD97 | |
| Arrived | 2019365007 | 12/31/2019 00:39:00 | LD97 | |
| Transport | 2019365004 | 12/31/2019 00:47:00 | R97 | |
| Cleared | 2019365007 | 12/31/2019 00:50:00 | LD97 | |
| At Hospital | 2019365004 | 12/31/2019 00:59:00 | R97 | |
| Dispatched | 2019365017 | 12/31/2019 01:04:00 | R99 | |
| En-Route | 2019365017 | 12/31/2019 01:05:00 | R99 | |
| Arrived | 2019365017 | 12/31/2019 01:12:00 | R99 | |
| Cleared | 2019365004 | 12/31/2019 01:16:00 | R97 | |
| Expected Result | ||||
| inci_id | unitcode | Dispatched | Arrived | Response Time |
| 2019365004 | R97 | 12/31/2019 00:26:00 | 12/31/2019 00:34:00 | 08:00 |
| Arrived Time - Dispatch Time |
Hi,
Write these measures
D = CALCULATE(MIN(Data[timestamp]),Data[descript]="Dispatched")A = CALCULATE(MIN(Data[timestamp]),Data[descript]="Arrived")Response time = [A]-[D]
Hope this helps.
- DarrelDonatto4 years agoFrequent Visitor
Thank you so much... This works well when used in a Matrix that groups by incident id and unit. I modified it slightly to get the format I needed:
Response time = If([A]=0," ", FORMAT([A]-[D],"h:mm:ss"))Is there a way to get the Maximum time to show in the incident id part of the matrix instead of the minimum? - Ashish_Mathur4 years agoSuper User
You are welcome. I do not understand your requirement. Please show the expected result very clearly.
- DarrelDonatto4 years agoFrequent Visitor
I am looking to get the maximum unit response time to appear on the line for the incident ID. Currently, I am getting the minimum time for all incident ids. For this case, instead of the 6:50 it should show 13:57.
- Ashish_Mathur4 years agoSuper User
Hi,
Try this measure
Response time_new = MAXX(Values(Data[Inci_id]),[Response time])
Hope this helps.
- DarrelDonatto4 years agoFrequent Visitor
That is still giving me the least or minimum time of all units for that Incident under the Incident ID row. I am trying to get the maximum time.
- Ashish_Mathur4 years agoSuper User
Hi,
Share the link from where i can download your PBI file.