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
Newbie12345
Regular Visitor

HELP!! DAX : Date Diff

Hi All,
Please help me around with the below query.
Topic: DAX
Query:
I want to calculate the date diff between 2 dates ( of each category) , attaching the screen-shot for your kind reference. 

Newbie12345_0-1702985102035.png

Thanks in Advance!

2 ACCEPTED SOLUTIONS
Fowmy
Super User
Super User

@Newbie12345 

Use this measure as a calculated column in your table and make sure to change the table name as per yours:

Date Diff = 
VAR __MaxDate = 
    CALCULATE(
        MAX( Table03[Date] ) , 
        ALLEXCEPT(Table03 , Table03[ID] , Table03[Category] )
    )
VAR __PrevDate = 
    CALCULATE(
        MAX( Table03[Date] ) , 
        Table03[Date] < __MaxDate,
        ALLEXCEPT(Table03 , Table03[ID] , Table03[Category] )
    )
RETURN
    IF( Table03[Date] =  __MaxDate && __PrevDate <> BLANK() ,INT (__MaxDate - __PrevDate ) ) 
Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

View solution in original post

Dangar332
Super User
Super User

Hi, @Newbie12345 

make a new column using below code

Column = 
var a = 'Table'[date]
var b = 'Table'[id]
var c= 'Table'[category]
var d = MAXX(FILTER('Table','Table'[date]<a && 'Table'[category]=c && 'Table'[id]=b),'Table'[date]) 
var e=  IF(d=BLANK(),'Table'[date],d)
var f= CONVERT('Table'[date]-e,INTEGER)
return
f

 

just adjust table and column name 

View solution in original post

2 REPLIES 2
Dangar332
Super User
Super User

Hi, @Newbie12345 

make a new column using below code

Column = 
var a = 'Table'[date]
var b = 'Table'[id]
var c= 'Table'[category]
var d = MAXX(FILTER('Table','Table'[date]<a && 'Table'[category]=c && 'Table'[id]=b),'Table'[date]) 
var e=  IF(d=BLANK(),'Table'[date],d)
var f= CONVERT('Table'[date]-e,INTEGER)
return
f

 

just adjust table and column name 

Fowmy
Super User
Super User

@Newbie12345 

Use this measure as a calculated column in your table and make sure to change the table name as per yours:

Date Diff = 
VAR __MaxDate = 
    CALCULATE(
        MAX( Table03[Date] ) , 
        ALLEXCEPT(Table03 , Table03[ID] , Table03[Category] )
    )
VAR __PrevDate = 
    CALCULATE(
        MAX( Table03[Date] ) , 
        Table03[Date] < __MaxDate,
        ALLEXCEPT(Table03 , Table03[ID] , Table03[Category] )
    )
RETURN
    IF( Table03[Date] =  __MaxDate && __PrevDate <> BLANK() ,INT (__MaxDate - __PrevDate ) ) 
Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

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

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.