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

Learn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register now

Reply
powerbiuser101
Advocate I
Advocate I

Diff between 2 values same column, based on value from another column

Hi,

 

I have n number of tickets. Each ticket has a created and changed date. Example:

 

TicketCreateChangeDesired Result
1102.01.201802.02.20181
1102.01.201802.04.20182
1102.01.201802.08.20184

 

I want to filter based on [Ticket], and diff between the [Change] dates and input that into a [Desired Result] column. One catch is, the 1st value for each ticket uses [Create] - [Change] instead. 

 

Where I'm at, I used rankx to create a calculated column to rank the tickets. I'm thinking of creating another calculated column to then rank based on [Change]. And then somehow use this new column as a reference for the desired result. But this approach seems overly complex.

 

Alternatively, maybe I could diff between [Create] and [Change] for each row, and then do the subtraction with current row and previous row, filtered by [Ticket]? But I'm also unable to figure out the proper DAX expression for that. 

1 ACCEPTED SOLUTION
Zubair_Muhammad
Community Champion
Community Champion

Hi @powerbiuser101

 

Try this Calculated Column

 

Desired Result =
VAR First_Date =
    CALCULATE (
        MIN ( TableName[Change] ),
        ALLEXCEPT ( TableName, TableName[Ticket] )
    )
VAR PreviousChange =
    CALCULATE (
        MAX ( TableName[Change] ),
        FILTER (
            ALLEXCEPT ( TableName, TableName[Ticket] ),
            TableName[Change] < EARLIER ( TableName[Change] )
        )
    )
RETURN
    IF (
        TableName[Change] = First_Date,
        DATEDIFF ( TableName[Create], TableName[Change], DAY ),
        DATEDIFF ( PreviousChange, TableName[Change], DAY )
    )

View solution in original post

3 REPLIES 3
Zubair_Muhammad
Community Champion
Community Champion

Hi @powerbiuser101

 

Try this Calculated Column

 

Desired Result =
VAR First_Date =
    CALCULATE (
        MIN ( TableName[Change] ),
        ALLEXCEPT ( TableName, TableName[Ticket] )
    )
VAR PreviousChange =
    CALCULATE (
        MAX ( TableName[Change] ),
        FILTER (
            ALLEXCEPT ( TableName, TableName[Ticket] ),
            TableName[Change] < EARLIER ( TableName[Change] )
        )
    )
RETURN
    IF (
        TableName[Change] = First_Date,
        DATEDIFF ( TableName[Create], TableName[Change], DAY ),
        DATEDIFF ( PreviousChange, TableName[Change], DAY )
    )

Thanks @Zubair_Muhammad

 

It works beautifully! 

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

February Power BI Update Carousel

Power BI Monthly Update - February 2026

Check out the February 2026 Power BI update to learn about new features.

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.