Forum Discussion
axk180022
Helper II
5 years agoCalculate Difference between 2 rows based on another column filter
I would want to find the difference in the GenHours for each serialid. Currently this is how my table looks on power BI. I have filtered the latest and 2nd latest date for each serialid. ...
- 5 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.
DarrelDonatto
4 years agoFrequent Visitor
I am trying to do something similar, but different.
For a given call (inci_id) AND a given unit (unitcode), I am trying to calculate the time difference between dispatch events (transtype). The problem is that these values are contained within different rows and not consecutive. I have attached a sample of my dataset.
| closecode | console | descript | inci_id | radorev | timeinsecs | timestamp | transtype | unitcode | userid |
| CONSOLE2 | Dispatched | 2019365004 | R | 1598 | 12/31/2019 0:26 | D | R97 | BMCGARY | |
| CONSOLE4 | En-Route | 2019365004 | R | 1666 | 12/31/2019 0:27 | E | R97 | ASABATINO | |
| CONSOLE2 | Dispatched | 2019365007 | R | 2050 | 12/31/2019 0:34 | D | LD97 | BMCGARY | |
| CONSOLE2 | Arrived | 2019365004 | R | 2092 | 12/31/2019 0:34 | A | R97 | BMCGARY | |
| CONSOLE2 | En-Route | 2019365007 | R | 2159 | 12/31/2019 0:35 | E | LD97 | BMCGARY | |
| CONSOLE2 | Arrived | 2019365007 | R | 2378 | 12/31/2019 0:39 | A | LD97 | BMCGARY | |
| CONSOLE2 | Transport | 2019365004 | R | 2877 | 12/31/2019 0:47 | T | R97 | BMCGARY | |
| FIR | CONSOLE2 | Cleared | 2019365007 | R | 3025 | 12/31/2019 0:50 | C | LD97 | BMCGARY |
| CONSOLE2 | At Hospital | 2019365004 | R | 3550 | 12/31/2019 0:59 | H | R97 | BMCGARY | |
| CONSOLE2 | Dispatched | 2019365017 | R | 3870 | 12/31/2019 1:04 | D | R99 | BMCGARY | |
| CONSOLE2 | En-Route | 2019365017 | R | 3940 | 12/31/2019 1:05 | E | R99 | BMCGARY | |
| CONSOLE2 | Arrived | 2019365017 | R | 4336 | 12/31/2019 1:12 | A | R99 | BMCGARY | |
| FIR | CONSOLE2 | Cleared | 2019365004 | R | 4611 | 12/31/2019 1:16 | C | R97 | BMCGARY |
Here is the file: https://drive.google.com/file/d/1KNGslhWB4YsFuRbjGOesiLmfegxLOqEE/view?usp=sharing
For example - for inci_id 2019365004 and unit R97 - I want to know the time difference between Dispatched and Arrived.
Can you suggest a solution?
Thanks in advance
Darrel Donatto
Fire Chief, Palm Beach Fire Rescue
Ashish_Mathur
Super User
4 years agoHi,
Show the expected result very clearly.