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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
qwertzuiop
Advocate III
Advocate III

date difference per value

Hello dear Power BI Community

 

Following problem:

I would like to add in Power BI the 3th column given these informations:

It should calculate the date difference per Product off the row above.

 

ProductDateDate_Difference_per_Product
A01.06.20220
B09.06.20220
A10.06.20229
A15.06.20225
B20.06.202211
B25.06.20225

 

Thank you very much for your contribution.

 

Cheers

qwertzuiop

1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi,

Please check the below picture and the attached pbix file.

It is for creating a new column.

 

Picture3.png

 

Date Diff per Product CC =
VAR _previousdate =
    MAXX (
        FILTER (
            Data,
            Data[Product] = EARLIER ( Data[Product] )
                && Data[Date] < EARLIER ( Data[Date] )
        ),
        Data[Date]
    )
RETURN
    IF ( _previousdate = BLANK (), 0, INT ( Data[Date] - _previousdate ) )

 

    Microsoft MVP




If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.





LinkedIn
Visit my LinkedIn page





Outlook Booking
Schedule a short Teams meeting to discuss your question.




View solution in original post

3 REPLIES 3
ddpl
Solution Sage
Solution Sage

@qwertzuiop try this

 

Column = var _A = 'yourTable'[Product]

         var _B = CALCULATE(MAX('yourTable'[Date]),FILTER('yourTable','yourTable'[Date] <EARLIER('yourTable'[Date])),'yourTable'[Product] = _A)
         var _C = DATEDIFF('yourTable'[Date],_B,DAY)

         return

         if(_C = BLANK(),0,abs(_C)
Jihwan_Kim
Super User
Super User

Hi,

Please check the below picture and the attached pbix file.

It is for creating a new column.

 

Picture3.png

 

Date Diff per Product CC =
VAR _previousdate =
    MAXX (
        FILTER (
            Data,
            Data[Product] = EARLIER ( Data[Product] )
                && Data[Date] < EARLIER ( Data[Date] )
        ),
        Data[Date]
    )
RETURN
    IF ( _previousdate = BLANK (), 0, INT ( Data[Date] - _previousdate ) )

 

    Microsoft MVP




If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.





LinkedIn
Visit my LinkedIn page





Outlook Booking
Schedule a short Teams meeting to discuss your question.




Dear Jihwan_Kim

PREVIEW
 
You solution here should work with my problem here as posted on the Forum , but I cannot get it to work. Should you have a moment to spare, may I ask you to please have a look? The applicable Power BI file is here. 
 
I sincerely thank you!
 
W
 

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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