Forum Discussion

qwertzuiop's avatar
qwertzuiop
Advocate III
4 years ago
Solved

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

  • Hi,

    Please check the below picture and the attached pbix file.

    It is for creating a new column.

     

     

    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 ) )
    

3 Replies

  • Hi,

    Please check the below picture and the attached pbix file.

    It is for creating a new column.

     

     

    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 ) )
    
    • Water's avatar
      Water
      Helper II

      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
       
  • ddpl's avatar
    ddpl
    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)