Forum Discussion

DaniBi92's avatar
DaniBi92
New Member
5 years ago

DATEDIFF with values in different Rows and Fields

Hi,

is it possible to use a DATEDIFF formulas with values in different Rows and Fields(or another DAX formulas)?

For example, i 've the following Data:

ITEMSTATUSDATE1        DATE2
XXXReceipt  01/05/2021 
XXXDelivery          05/05/2021
YYYReceipt04/04/2021 
ZZZReceipt30/04/2021 
YYYDelivery         07/04/2021
ZZZDelivery         11/05/2021

The result that i need is the sum of the days difference by Item. In my exemple the result must be 18:

ITEMDATE1          DATE2RESULTS
XXX01/05/2021        05/05/20214
YYY04/04/2021        07/04/20213
ZZZ30/04/2021        11/05/202111
           RESULT:18

Is there a DAX formulas to achive this result?

Thanks in advance.

3 Replies

  • DaniBi92 

    You can create a DX table with the following code.  Click New Table under the Modeling tab and paste the code given below, rename the table name as per yours.

    Result Table = 
    ADDCOLUMNS(
        ADDCOLUMNS(
            VALUES(Table1[ITEM]),
            "DATE1", CALCULATE(MIN(Table1[DATE1])),
            "DATE2", CALCULATE(MIN(Table1[DATE2]))
        ),
        "RESULT", DATEDIFF([DATE1],[DATE2],DAY)
    )

     

     



  • Hi, DaniBi92 

    Please check the below picture and the sample pbix file's link down below.

    All measures are in the sample b pbix file, and all steps are numbered in front of each measure.

     

     

    https://www.dropbox.com/s/4lwg972lhq9ki9q/danibi.pbix?dl=0 

     

     

    Hi, My name is Jihwan Kim.

     

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

     

    Linkedin: linkedin.com/in/jihwankim1975/

    Twitter: twitter.com/Jihwan_JHKIM