Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!
Hello,
I have been trying to compute this problem for a while now and without any progress. I managed to do a workaround but am professionally curious whether it is possible to compute in PowerBI directly.
I have a table with box IDs, start time, end time and time difference between start time and end time for each row, where start and end time mark the time interval during which a box was full. What I am trying to compute is the portion of time during which the box is full based on a slicer. (For example what portion of time was the box full between 2nd and 5th May 2019?).
The calculation works fine if the slicer is in original position, i.e. the data is not sliced. But when I move the slicer, the calucaltion gets distorted because originally I based my calculation on the time difference column. How can I compute time difference for each row in PowerBI measure? For example: The box is full from 1st May till 7th May and I move the slicer to be from 3rd till 5th May. Hence, the result should give me that this box was 100% full. But I need to calculate that if MIN Selected value of slicer is larger than start time, calculate DATEDIFF(MIN selected value, end time) etc.. But DATEDIFF does not work on single rows. Is there a similar function working on rows? Any other ideas for a workaround? Below I share a sample of my data.
Thanks for any help!
Solved! Go to Solution.
Hi @Anonymous ,
I create a sample that can be calculated duration between the selected date and the end date, or if it is not selected, calculated it between the start date and the end date. You can reference it to modify yours.
Table = CALENDAR(DATE(2019,1,1),DATE(2019,12,31)) selected time = FORMAT('Table'[Date],"hh:mm:ss")
Note: when you create the calendar table, you need to add the minimum date of the start date and the maximum of the end time. And there is no relationship between the two tables.
start time = FORMAT(Table1[start],"hh:mm:ss")
end time = FORMAT(Table1[end],"hh:mm:ss")
date_diff_min = var a = DATEDIFF(Table1[start],Table1[end],DAY) var b = DATEDIFF(Table1[start time],Table1[end time],MINUTE) return a*24*60+b
Measure = var a = DATEDIFF(MIN('Table'[Date]),MAX(Table1[end]),DAY) var b = DATEDIFF(MIN('Table'[selected time]),MAX(Table1[end time]),MINUTE) var c = IF( MIN('Table'[Date]) > MAX(Table1[start]) && MIN('Table'[Date]) < MAX(Table1[end]), a*24*60+b, SUM(Table1[date_diff_min])) return c
Best Regards,
Xue Ding
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi @Anonymous ,
I create a sample that can be calculated duration between the selected date and the end date, or if it is not selected, calculated it between the start date and the end date. You can reference it to modify yours.
Table = CALENDAR(DATE(2019,1,1),DATE(2019,12,31)) selected time = FORMAT('Table'[Date],"hh:mm:ss")
Note: when you create the calendar table, you need to add the minimum date of the start date and the maximum of the end time. And there is no relationship between the two tables.
start time = FORMAT(Table1[start],"hh:mm:ss")
end time = FORMAT(Table1[end],"hh:mm:ss")
date_diff_min = var a = DATEDIFF(Table1[start],Table1[end],DAY) var b = DATEDIFF(Table1[start time],Table1[end time],MINUTE) return a*24*60+b
Measure = var a = DATEDIFF(MIN('Table'[Date]),MAX(Table1[end]),DAY) var b = DATEDIFF(MIN('Table'[selected time]),MAX(Table1[end time]),MINUTE) var c = IF( MIN('Table'[Date]) > MAX(Table1[start]) && MIN('Table'[Date]) < MAX(Table1[end]), a*24*60+b, SUM(Table1[date_diff_min])) return c
Best Regards,
Xue Ding
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
User | Count |
---|---|
124 | |
108 | |
99 | |
62 | |
62 |
User | Count |
---|---|
137 | |
115 | |
102 | |
71 | |
61 |