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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
gaspar13
Frequent Visitor

Calc date difference between rows by unique ID

Hello,

 

I am trying to calculate the difference between the max and min dates (in the [As of Date] field) across multiple rows. The issue is that I need the difference to be calculated for each unique [Internal ID] (another field) and the difference should be between the minimum of Status "Unqualified" and the maximum of Status "Closed - Won", "Closed - Pending" and "Closed - Confirmed".

 

The table is below and here is the code I have so far (with the help of this forum). But the measure returns the same number for all records.

 

Not sure if I should break this up into tables or can this be done in measure? From the data in this table, I would expect this result:

Internal IDDateDiffCalc
1234513max of 1/12/22, 1/13/22, 1/14/22 less min of 1/1/22, 1/2/22, 1/3/22

 

 

Internal IDStatusAs of Date (M/D/YY)
12345Unqualified1/1/22
12345Unqualified1/2/22
12345Unqualified1/3/22
12345Closed - Won1/13/22
12345Closed - Confirmed1/12/22
12345Closed - Pending1/12/22
12345Closed - Pending1/14/22

 

My measure so far...

 

DateDiff =
VAR Type1 =
    CALCULATE (
        MIN ( 'AsOfGrossSalesRecordResults667'[As Of Date].[Date] ),
        'AsOfGrossSalesRecordResults667'[Status] = "Unqualifed"
    )
VAR Type2 =
    CALCULATE (
        MAX ( 'AsOfGrossSalesRecordResults667'[As Of Date].[Date] ),
        'AsOfGrossSalesRecordResults667'[Status] = "Closed - Lost",
        'AsOfGrossSalesRecordResults667'[Status] = "Closed - Pending",
        'AsOfGrossSalesRecordResults667'[Status] = "Closed - Won"
    )
RETURN
    FORMAT ( ( Type2 - Type1 )"Standard" )
 
Thanks in advance!
2 REPLIES 2
amitchandak
Super User
Super User

@gaspar13 , based on what I got, Try like

 

DateDiff =
VAR Type1 =
CALCULATE (
MIN ( 'AsOfGrossSalesRecordResults667'[As Of Date].[Date] ),
Filter('AsOfGrossSalesRecordResults667', 'AsOfGrossSalesRecordResults667'[Status] = "Unqualifed"), allexcept('AsOfGrossSalesRecordResults667','AsOfGrossSalesRecordResults667'[Internal ID])
)
VAR Type2 =
CALCULATE (
MAX ( 'AsOfGrossSalesRecordResults667'[As Of Date].[Date] ),
Filter('AsOfGrossSalesRecordResults667', 'AsOfGrossSalesRecordResults667'[Status] = "Closed - Lost" ||
'AsOfGrossSalesRecordResults667'[Status] = "Closed - Pending" ||
'AsOfGrossSalesRecordResults667'[Status] = "Closed - Won" ) , allexcept('AsOfGrossSalesRecordResults667','AsOfGrossSalesRecordResults667'[Internal ID])
)
RETURN
FORMAT ( ( Type2 - Type1 ), "Standard" )

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Hi Amit,

 

It's close, but I'm getting results like 44,680 for a lot of records with different Internal IDs (see below).

 

I'm putting the DateDiff measure plus the Internal ID into a table viz.

 

gaspar13_0-1651709026569.png

 

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.

Top Solution Authors