Starting December 3, join live sessions with database experts and the Microsoft product team to learn just how easy it is to get started
Learn moreGet certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now
Hello!
I'm new to PBI and DAX and am struggling with this problem. Please see attached .pbox with sample data
I have to tables, Break Schedule and Down Time.
I would like to add a column to Down Time that displays Yes when a Down Time is likely a break.
Here is the logic that I'm trying to implement to determine if a down time is a break:
1. The down time duration must be longer than the break duration
2. The down time has to start within 1 hour of the scheduled break start time.
Using this logic, I would expect Row 2 and Row 5 to be marked as a break, as seen below:
I have a vague idea of what to do, but don't have a clue how to go about it in PBI/DAX.
Any guidance on this will be greatly appreciated!!!
Thanks,
Sidd
Solved! Go to Solution.
Hi Sidd,
You can try a calculated column like this.
Column = VAR breaktime1 = CALCULATE ( VALUES ( 'Break Schedule'[Break Start] ), 'Break Schedule'[Index] = 1 ) VAR breakduration1 = CALCULATE ( VALUES ( 'Break Schedule'[Duration] ), 'Break Schedule'[Index] = 1 ) VAR breaktime2 = CALCULATE ( VALUES ( 'Break Schedule'[Break Start] ), 'Break Schedule'[Index] = 2 ) VAR breakduration2 = CALCULATE ( VALUES ( 'Break Schedule'[Duration] ), 'Break Schedule'[Index] = 2 ) VAR breaktime3 = CALCULATE ( VALUES ( 'Break Schedule'[Break Start] ), 'Break Schedule'[Index] = 3 ) VAR breakduration3 = CALCULATE ( VALUES ( 'Break Schedule'[Duration] ), 'Break Schedule'[Index] = 3 ) RETURN IF ( 'Down Time'[Duration] <= MIN ( 'Break Schedule'[Duration] ), "No", IF ( ABS ( DATEDIFF ( TIMEVALUE ( [Time] ), breaktime1, MINUTE ) ) <= 60 && [Duration] > breakduration1, "Yes", IF ( ABS ( DATEDIFF ( TIMEVALUE ( [Time] ), breaktime2, MINUTE ) ) <= 60 && [Duration] > breakduration2, "Yes", IF ( ABS ( DATEDIFF ( TIMEVALUE ( [Time] ), breaktime3, MINUTE ) ) <= 60 && [Duration] > breakduration3, "Yes", "No" ) ) ) )
I added a test row to verify the formula above.
Best Regards,
Dale
Hi Sidd,
You can try a calculated column like this.
Column = VAR breaktime1 = CALCULATE ( VALUES ( 'Break Schedule'[Break Start] ), 'Break Schedule'[Index] = 1 ) VAR breakduration1 = CALCULATE ( VALUES ( 'Break Schedule'[Duration] ), 'Break Schedule'[Index] = 1 ) VAR breaktime2 = CALCULATE ( VALUES ( 'Break Schedule'[Break Start] ), 'Break Schedule'[Index] = 2 ) VAR breakduration2 = CALCULATE ( VALUES ( 'Break Schedule'[Duration] ), 'Break Schedule'[Index] = 2 ) VAR breaktime3 = CALCULATE ( VALUES ( 'Break Schedule'[Break Start] ), 'Break Schedule'[Index] = 3 ) VAR breakduration3 = CALCULATE ( VALUES ( 'Break Schedule'[Duration] ), 'Break Schedule'[Index] = 3 ) RETURN IF ( 'Down Time'[Duration] <= MIN ( 'Break Schedule'[Duration] ), "No", IF ( ABS ( DATEDIFF ( TIMEVALUE ( [Time] ), breaktime1, MINUTE ) ) <= 60 && [Duration] > breakduration1, "Yes", IF ( ABS ( DATEDIFF ( TIMEVALUE ( [Time] ), breaktime2, MINUTE ) ) <= 60 && [Duration] > breakduration2, "Yes", IF ( ABS ( DATEDIFF ( TIMEVALUE ( [Time] ), breaktime3, MINUTE ) ) <= 60 && [Duration] > breakduration3, "Yes", "No" ) ) ) )
I added a test row to verify the formula above.
Best Regards,
Dale
Thanks Dale! Your solution was taught me how to use PowerBI a little better. Cheers!
Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.
User | Count |
---|---|
88 | |
85 | |
82 | |
65 | |
49 |
User | Count |
---|---|
138 | |
110 | |
104 | |
66 | |
64 |