Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
siddp
Regular Visitor

add yes/no column if row meets certain criteria

Hello!

 

I'm new to PBI and DAX and am struggling with this problem. Please see attached .pbox with sample data

Breaks.pbix

 

I have to tables, Break Schedule and Down Time.

Break Scheduledown times

 

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:

down time with breaks

 

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

1 ACCEPTED SOLUTION
v-jiascu-msft
Microsoft Employee
Microsoft Employee

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.

add_yesno_column_if_row_meets_certain_criteria

 

Best Regards,

Dale

 

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
v-jiascu-msft
Microsoft Employee
Microsoft Employee

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.

add_yesno_column_if_row_meets_certain_criteria

 

Best Regards,

Dale

 

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thanks Dale! Your solution was taught me how to use PowerBI a little better. Cheers! Smiley Very Happy

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.