The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
Hi Team,
We're having trouble calculating time elapsed for vehicles that are idling. Sensor data for each vehicle is being sent and we need to know how much time a vehicle (bus_id) has spent in idle (sensor_value < 701).
I created a new colum:
But I cant get it to work. Here's some sample data to give you an idea of what we're working with
Any help would be greatly aprecciated
Thanks.
Thanks for the promt reply. First time poster so I really appreciate the help.
Attached data and expected results. Hopefully I got it right this time.
ID | bus_id | sensor_value | date1 | time1 | Date | Expected |
14618 | Bus_002 | 699.75 | 9/25/2024 | 2:29:27 PM | 9/25/2024 2:29:27 PM | 0 |
14619 | Bus_002 | 700.25 | 9/25/2024 | 2:29:28 PM | 9/25/2024 2:29:28 PM | 1 |
14620 | Bus_002 | 701 | 9/25/2024 | 2:29:28 PM | 9/25/2024 2:29:28 PM | 0 |
14621 | Bus_002 | 699.875 | 9/25/2024 | 2:29:28 PM | 9/25/2024 2:29:28 PM | 1 |
14622 | Bus_002 | 699.25 | 9/25/2024 | 2:29:32 PM | 9/25/2024 2:29:32 PM | 4 |
14634 | Bus_002 | 700.125 | 9/25/2024 | 2:29:36 PM | 9/25/2024 2:29:36 PM | 4 |
14635 | Bus_002 | 699.875 | 9/25/2024 | 2:29:36 PM | 9/25/2024 2:29:36 PM | 1 |
14636 | Bus_002 | 699.625 | 9/25/2024 | 2:29:36 PM | 9/25/2024 2:29:36 PM | 1 |
14637 | Bus_002 | 699.375 | 9/25/2024 | 2:29:37 PM | 9/25/2024 2:29:37 PM | 1 |
14638 | Bus_002 | 700.75 | 9/25/2024 | 2:29:37 PM | 9/25/2024 2:29:37 PM | 1 |
14639 | Bus_002 | 700.375 | 9/25/2024 | 2:29:37 PM | 9/25/2024 2:29:37 PM | 1 |
14900 | Bus_002 | 700.25 | 9/25/2024 | 2:31:58 PM | 9/25/2024 2:31:58 PM | 141 |
14901 | Bus_003 | 699.75 | 9/25/2024 | 2:31:58 PM | 9/25/2024 2:31:58 PM | 1 |
14902 | Bus_003 | 699.875 | 9/25/2024 | 2:31:59 PM | 9/25/2024 2:31:59 PM | 1 |
14903 | Bus_003 | 700.125 | 9/25/2024 | 2:31:59 PM | 9/25/2024 2:31:59 PM | 1 |
14904 | Bus_003 | 700.5 | 9/25/2024 | 2:32:03 PM | 9/25/2024 2:32:03 PM | 4 |
14931 | Bus_003 | 700 | 9/25/2024 | 2:32:13 PM | 9/25/2024 2:32:13 PM | 10 |
14932 | Bus_003 | 699.625 | 9/25/2024 | 2:32:13 PM | 9/25/2024 2:32:13 PM | 1 |
14933 | Bus_003 | 701.25 | 9/25/2024 | 2:32:14 PM | 9/25/2024 2:32:14 PM | 0 |
14934 | Bus_003 | 699.5 | 9/25/2024 | 2:32:15 PM | 9/25/2024 2:32:15 PM | 1 |
14935 | Bus_003 | 699.5 | 9/25/2024 | 2:32:15 PM | 9/25/2024 2:32:15 PM | 1 |
14936 | Bus_003 | 701 | 9/25/2024 | 2:32:15 PM | 9/25/2024 2:32:15 PM | 0 |
14937 | Bus_003 | 699.875 | 9/25/2024 | 2:32:16 PM | 9/25/2024 2:32:16 PM | 1 |
14938 | Bus_003 | 700.5 | 9/25/2024 | 2:32:16 PM | 9/25/2024 2:32:16 PM | 1 |
14939 | Bus_003 | 700.25 | 9/25/2024 | 2:32:16 PM | 9/25/2024 2:32:16 PM | 1 |
Hi, @Castillo3CS
I modified some of your formulas.
Next = MAXX(FILTER(Ralentis,
Ralentis[bus_id]=EARLIER(Ralentis[bus_id]) &&
Ralentis[Date]<EARLIER(Ralentis[Date])
),Ralentis[Date])
Column = IF([sensor_value]>=701, 0,IF(ISBLANK([Next]),
ABS(DATEDIFF([Date],NOW(),SECOND)),
ABS(DATEDIFF([Date],[Next],SECOND))
)
)
Please check, is this the result you expect?
Best Regards,
Community Support Team _Charlotte
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi @Anonymous ,
I'm still getting some very odd values for time difference, notice the 1125431 and the 1125280. If we do the math between the two dates there’s now way we’re getting those numbers.
I was going to try something with index columns but I'm in the middle of implementing it, so I’m not sure it’ll work.
Thanks a lot for the help.
Those are different buses. Change the formula to return null instead.
My apologies, just noticed the mistake. When I sent the sample data I sorted it by Bus, the original data file comes with the IDs mixed, we have over 100 buses and data for them can come at the same time but recorded in different rows.
It looks something like this:
bus1 - time - value
bus1 - time - value
bus2 - time - vaue
bus1 - time - value
bus3 - time - value
.....
Hopefully this makes sense.
Please provide sample data that fully covers your issue.
Please show the expected outcome based on the sample data you provided.
Here's the sampel data arranged to look like ou table.
ID | bus_id | sensor_value | date1 | time1 | Date | Expected |
14618 | Bus_002 | 699.75 | 9/25/2024 | 2:29:27 PM | 9/25/2024 2:29:27 PM | 0 |
14619 | Bus_002 | 700.25 | 9/25/2024 | 2:29:28 PM | 9/25/2024 2:29:28 PM | 1 |
14620 | Bus_002 | 701 | 9/25/2024 | 2:29:28 PM | 9/25/2024 2:29:28 PM | 0 |
14901 | Bus_003 | 699.75 | 9/25/2024 | 2:31:58 PM | 9/25/2024 2:31:58 PM | 0 |
14902 | Bus_003 | 699.875 | 9/25/2024 | 2:31:59 PM | 9/25/2024 2:31:59 PM | 1 |
14903 | Bus_003 | 700.125 | 9/25/2024 | 2:31:59 PM | 9/25/2024 2:31:59 PM | 0 |
14904 | Bus_003 | 700.5 | 9/25/2024 | 2:32:03 PM | 9/25/2024 2:32:03 PM | 4 |
14621 | Bus_002 | 699.875 | 9/25/2024 | 2:29:28 PM | 9/25/2024 2:29:28 PM | 0 |
14622 | Bus_002 | 699.25 | 9/25/2024 | 2:29:32 PM | 9/25/2024 2:29:32 PM | 4 |
14634 | Bus_002 | 700.125 | 9/25/2024 | 2:29:36 PM | 9/25/2024 2:29:36 PM | 4 |
14635 | Bus_002 | 699.875 | 9/25/2024 | 2:29:36 PM | 9/25/2024 2:29:36 PM | 0 |
14931 | Bus_003 | 700 | 9/25/2024 | 2:32:13 PM | 9/25/2024 2:32:13 PM | 10 |
14932 | Bus_003 | 699.625 | 9/25/2024 | 2:32:13 PM | 9/25/2024 2:32:13 PM | 0 |
14636 | Bus_002 | 699.625 | 9/25/2024 | 2:29:36 PM | 9/25/2024 2:29:36 PM | 0 |
14637 | Bus_002 | 699.375 | 9/25/2024 | 2:29:37 PM | 9/25/2024 2:29:37 PM | 1 |
14936 | Bus_003 | 701 | 9/25/2024 | 2:32:15 PM | 9/25/2024 2:32:14 PM | 2 |
14937 | Bus_003 | 699.875 | 9/25/2024 | 2:32:16 PM | 9/25/2024 2:32:15 PM | 1 |
14938 | Bus_003 | 700.5 | 9/25/2024 | 2:32:16 PM | 9/25/2024 2:32:15 PM | 0 |
14638 | Bus_002 | 700.75 | 9/25/2024 | 2:29:37 PM | 9/25/2024 2:29:37 PM | 1 |
14639 | Bus_002 | 700.375 | 9/25/2024 | 2:29:37 PM | 9/25/2024 2:29:37 PM | 1 |
14900 | Bus_002 | 700.25 | 9/25/2024 | 2:31:58 PM | 9/25/2024 2:31:58 PM | 141 |
14933 | Bus_003 | 701.25 | 9/25/2024 | 2:32:14 PM | 9/25/2024 2:32:15 PM | 0 |
14934 | Bus_003 | 699.5 | 9/25/2024 | 2:32:15 PM | 9/25/2024 2:32:16 PM | 1 |
14935 | Bus_003 | 699.5 | 9/25/2024 | 2:32:15 PM | 9/25/2024 2:32:16 PM | 0 |
14939 | Bus_003 | 700.25 | 9/25/2024 | 2:32:16 PM | 9/25/2024 2:32:16 PM | 0 |
Hi,
I used these calculated column formulas
Date and time = Data[date1]+Data[time1]
Diff = if(ISBLANK(CALCULATE(MAX(Data[Date and time]),FILTER(Data,Data[bus_id]=EARLIER(Data[bus_id])&&Data[Date and time]<EARLIER(Data[Date and time])))),time(0,0,0),Data[Date and time]-CALCULATE(MAX(Data[Date and time]),FILTER(Data,Data[bus_id]=EARLIER(Data[bus_id])&&Data[Date and time]<EARLIER(Data[Date and time]))))
Hope this helps.
Let's only take a look at bus 2
| ID | bus_id | sensor_value | date1 | time1 | Date | Expected | | ----- | ------- | ------------ | --------- | ---------- | -------------------- | -------- | | 14618 | Bus_002 | 699.75 | 9/25/2024 | 2:29:27 PM | 9/25/2024 2:29:27 PM | 0 | | 14619 | Bus_002 | 700.25 | 9/25/2024 | 2:29:28 PM | 9/25/2024 2:29:28 PM | 1 | | 14620 | Bus_002 | 701 | 9/25/2024 | 2:29:28 PM | 9/25/2024 2:29:28 PM | 0 | | 14621 | Bus_002 | 699.875 | 9/25/2024 | 2:29:28 PM | 9/25/2024 2:29:28 PM | 0 | | 14622 | Bus_002 | 699.25 | 9/25/2024 | 2:29:32 PM | 9/25/2024 2:29:32 PM | 4 | | 14634 | Bus_002 | 700.125 | 9/25/2024 | 2:29:36 PM | 9/25/2024 2:29:36 PM | 4 | | 14635 | Bus_002 | 699.875 | 9/25/2024 | 2:29:36 PM | 9/25/2024 2:29:36 PM | 0 | | 14636 | Bus_002 | 699.625 | 9/25/2024 | 2:29:36 PM | 9/25/2024 2:29:36 PM | 0 | | 14637 | Bus_002 | 699.375 | 9/25/2024 | 2:29:37 PM | 9/25/2024 2:29:37 PM | 1 | | 14638 | Bus_002 | 700.75 | 9/25/2024 | 2:29:37 PM | 9/25/2024 2:29:37 PM | 1 | | 14639 | Bus_002 | 700.375 | 9/25/2024 | 2:29:37 PM | 9/25/2024 2:29:37 PM | 1 | | 14900 | Bus_002 | 700.25 | 9/25/2024 | 2:31:58 PM | 9/25/2024 2:31:58 PM | 141 |
could you pls explain how we get the expected output? why the last one is 141?
Proud to be a Super User!
you can try this
Proud to be a Super User!
Error was me copying the values to the sample table. I'm testing your solution but PowerBi is taking a very long time to create the new column. We have over 1.4 million rows so I'm not surprised. Will let you know once it’s done.
Hi @ryan_mayu , I had to terminate the process after 2 hours of "working on it", any ideas?
I don't have better solution for this. Maybe you can wait for longer time or let's see if anyone else have better solution for this.
Proud to be a Super User!
Please provide sample data that covers your issue or question completely, in a usable format (not as a screenshot).
Do not include sensitive information. Do not include anything that is unrelated to the issue or question.
Need help uploading data? https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-...
Please show the expected outcome based on the sample data you provided.
Want faster answers? https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447...
User | Count |
---|---|
77 | |
75 | |
36 | |
31 | |
28 |
User | Count |
---|---|
95 | |
81 | |
55 | |
48 | |
48 |