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

Prepping for a Fabric certification exam? Join us for a live prep session with exam experts to learn how to pass the exam. Register now.

Reply
POSPOS
Post Patron
Post Patron

Calculate difference between previous date of same column using DAX

Hi All,

I have a requirement to calculate the difference between date of the current line to the previous line of the same column.

Please find sample data below:

ProtocolReceivedStatusDate
A6/30/2022Assigned11/7/2022
A 6/30/2022In-Progress1/18/2023
A 6/30/2022Pre-Review2/6/2323
A 6/30/2022Agenda2/6/2023
A 6/30/2022Pre-Review2/15/2023
B7/10/2023Assigned7/15/2023
B7/10/2023In-Progress7/15/2323
B7/10/2023Agenda8/1/2023
B7/10/2023Pre-Review 8/10/2023
B7/10/2023Pre-Review8/15/2023

 

Expected Output:

ProtocolReceived DateStatusEffective DateNo. of days
A6/30/2022Assigned11/7/2022130
A 6/30/2022In-Progress1/18/202372
A 6/30/2022Pre-Review2/6/202319
A 6/30/2022Agenda2/6/20230
A 6/30/2022Pre-Review2/15/20239
B7/10/2023Assigned7/15/20235
B7/10/2023In-Progress7/15/20230
B7/10/2023Modified8/1/202317
B7/10/2023Pre-Review 8/10/20239
B7/10/2023Modified8/15/20235

 

1. First value of a group will be the received date minus effective date

2. The other values will be difference from the previous date of the effective date column.

POSPOS_0-1696963178410.png

 

I followed the blog below but this is not working when the dates are same as well the status are getting aggregated instead of showing it separately.

DAX Fridays! #85: Difference between dates in the same column

Could someone pleas advise how this can be solved using DAX.

Thank you.

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @POSPOS 

You can add a index column in power query first and apply it

vxinruzhumsft_0-1697081321028.png

Then create a calculated column

Column = var a=FILTER('Table',[Protocol]=EARLIER('Table'[Protocol]))
var b=MINX(FILTER(a,[Date]=MINX(a,[Date])),[Index])
return IF([Index]=b,DATEDIFF([Received],[Date],DAY),DATEDIFF(MAXX(FILTER(a,[Index]=EARLIER('Table'[Index])-1),[Date]),[Date],DAY))

Output

vxinruzhumsft_1-1697081435899.png

Best Regards!

Yolo Zhu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Hi @POSPOS 

You can add a index column in power query first and apply it

vxinruzhumsft_0-1697081321028.png

Then create a calculated column

Column = var a=FILTER('Table',[Protocol]=EARLIER('Table'[Protocol]))
var b=MINX(FILTER(a,[Date]=MINX(a,[Date])),[Index])
return IF([Index]=b,DATEDIFF([Received],[Date],DAY),DATEDIFF(MAXX(FILTER(a,[Index]=EARLIER('Table'[Index])-1),[Date]),[Date],DAY))

Output

vxinruzhumsft_1-1697081435899.png

Best Regards!

Yolo Zhu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

ThxAlot
Super User
Super User

Interval days.pbix

 

An index column is added to differentiate duplicated dates.

ThxAlot_0-1696970983941.png



Expertise = List.Accumulate(


        {Days as from Today},


        {Skills and Knowledge},


        (Current, Everyday) => Current & Day.LeanAndPractise(Everyday)


)



@ThxAlot  - Have you created index using DAX? Is there a way I can create index column using DAX.
Could you share you pbix pls.

Helpful resources

Announcements
May PBI 25 Carousel

Power BI Monthly Update - May 2025

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

May 2025 Monthly Update

Fabric Community Update - May 2025

Find out what's new and trending in the Fabric community.