Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.
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.
Thanks in Advance!
Solved! Go to Solution.
@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 ) )
⭕ Subscribe and learn Power BI from these videos
⚪ Website ⚪ LinkedIn ⚪ PBI User Group
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
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
@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 ) )
⭕ Subscribe and learn Power BI from these videos
⚪ Website ⚪ LinkedIn ⚪ PBI User Group
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
10 | |
9 | |
8 | |
8 | |
7 |
User | Count |
---|---|
13 | |
12 | |
11 | |
11 | |
8 |