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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Anonymous
Not applicable

Calculate number of days between dates in same column in power query

Dummy dataDummy dataimage.png    First picture is the dummy data on which i need to peform the calculation. Second picture is the end result. I need to calculate the difference between dates based on index column.

1 ACCEPTED SOLUTION
v-juanli-msft
Community Support
Community Support

Hi @Anonymous 

Create measures

Measure = CALCULATE(SUM('Table'[Date]),FILTER(ALLEXCEPT('Table','Table'[Object]),[Index]=MAX([Index])-1))

Measure 2 = IF([Measure]<>BLANK(),DATEDIFF([Measure],MAX('Table'[Date]),DAY))

Capture3.JPG

Best Regards
Maggie

 

Community Support Team _ Maggie Li
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
v-juanli-msft
Community Support
Community Support

Hi @Anonymous 

Create measures

Measure = CALCULATE(SUM('Table'[Date]),FILTER(ALLEXCEPT('Table','Table'[Object]),[Index]=MAX([Index])-1))

Measure 2 = IF([Measure]<>BLANK(),DATEDIFF([Measure],MAX('Table'[Date]),DAY))

Capture3.JPG

Best Regards
Maggie

 

Community Support Team _ Maggie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

I need an index column just like this, how can I created in power query

Stachu
Community Champion
Community Champion

you could add the previous date and previous object as new columns, as desribed here
https://www.thebiccountant.com/2018/07/12/fast-and-easy-way-to-reference-previous-or-next-rows-in-po...

then you can do simple if

if [Object]=[Previous Object] then [Date]-[Previous Date] else null

although you may need to add Duration.Days around the substracted dates, I wrote it from memory so not 100% sure it's needed



Did I answer your question? Mark my post as a solution!
Thank you for the kudos 🙂

Helpful resources

Announcements
PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

Top Solution Authors
Top Kudoed Authors