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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
alexpork
Frequent Visitor

DAX statement based on multiple conditions

Hello,

 

I am currently trying to use DAX to add a TIMEDIFF column based on multiple conditions below:

Capture.PNG

IF the ID is the same, and the Signifier column has a DSCN value followed by a RECO value on the same day, add a column that subtracts the time difference between those two rows. 

 

For example, since the second row and third row fulfills these conditions, it would subtract 17:17 and 8:31 and add the difference in a new column.

1 REPLY 1
AlB
Community Champion
Community Champion

Hi @alexpork 

Please always show your sample data in text-tabular format in addition to (or instead of) the screen captures. A screen cap doesn't allow people to readily copy the data and run a quick test and thus decreases the likelihood of your question being answered. Just use 'Copy table' in Power BI and paste it here.

 

Create a new calculated column in your table:

New column =
IF (
    Table1[Signifier] = "RECO",
    VAR previousRowInDay_ =
        CALCULATETABLE (
            ROW (
                "Signifier_", MAX ( Table1[Signifier] ),
                "DateTime_", MAX ( Table1[DateTime] )
            ),
            ALLEXCEPT ( Table1, Table1[ID] ),
            INT ( Table1[DateTime] ) = INT ( EARLIER ( Table1[DateTime] ) ),
            Table1[DateTime] < EARLIER ( Table1[DateTime] )
        )
    VAR isDSCN_ = MAXX ( previousRowInDay_, [Signifier_] ) = "DSCN"
    VAR previousTimeInDay_ = MAXX ( previousRowInDay_, [DateTime_] )
    VAR diffInMins_ = IF ( isDSCN_, ( Table1[DateTime] - previousTimeInDay_ ) * 24 * 60 )
                 // Time difference converted to minutes. Update if another unit required
    RETURN
        diffInMins_
)

 

Please mark the question solved when done and consider giving a thumbs up if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

SU18_powerbi_badge

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.