Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

Difference between MAX date and another date

Hi folks,

 

I am struggling with a DAX expression to get the difference between the max date in a slicer and the date of the invoices, I mean:

 

I have a table with clients, invoices and dates:

ClientInvoiceDate
client_1INV/000102/05/2018
client_1INV/000203/07/2018
client_1INV/000308/09/2018
client_2INV/000516/06/2018
client_2INV/001220/11/2018

 

And I have a slicer to select my dates, so, I would like to get the difference in days between the MAX(date) in the slicer and each one of my dates, like the following example:

ClientInvoiceDateMAX(date) in selectorDays
client_1INV/000102/05/201815/12/2018227
client_1INV/000203/07/201815/12/2018165
client_1INV/000308/09/201815/12/201898
client_2INV/000516/06/201815/12/2018182
client_2INV/001220/11/201815/12/201825

 

Where MAX(date) in selector comes from the slicer.

 

It would be nice if someone could help me, thanks in advance.

  • Hi Anonymous ,

     

    You could create two measures to get it.

    max date =
    MAXX ( ALLSELECTED ( 'Date'[Date] ), 'Date'[Date] )
    
    Days =
    DATEDIFF ( SELECTEDVALUE ( 'Table'[Date] ), [max date], DAY )

    Here is the result.

    Here is my test file for your reference.

     

3 Replies

  • Mariusz's avatar
    Mariusz
    Community Champion

    Hi Anonymous 

     

    You can create a measure like below.

    Days = DATEDIFF( SELECTEDVALUE( 'Table'[Date] ), MAX( dates[Date] ), DAY )

    Please see the attached file with the solution.

     

    Best Regards,
    Mariusz

    If this post helps, then please consider Accepting it as the solution.

    Please feel free to connect with me.
    Mariusz Repczynski


     

  • v-eachen-msft's avatar
    v-eachen-msft
    Community Support

    Hi Anonymous ,

     

    You could create two measures to get it.

    max date =
    MAXX ( ALLSELECTED ( 'Date'[Date] ), 'Date'[Date] )
    
    Days =
    DATEDIFF ( SELECTEDVALUE ( 'Table'[Date] ), [max date], DAY )

    Here is the result.

    Here is my test file for your reference.

     

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi v-eachen-msft 

       

      could it be possible to do it in a column instead of doing it in a measure?  The reason is that I want to use this calculated value in a selector.