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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

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.

1 ACCEPTED SOLUTION
v-eachen-msft
Community Support
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.

1-1.PNG

Here is my test file for your reference.

 

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

View solution in original post

3 REPLIES 3
v-eachen-msft
Community Support
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.

1-1.PNG

Here is my test file for your reference.

 

Community Support Team _ Eads
If this post helps, then please consider Accept it as the solution to help the other members find it.
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.

Mariusz
Community Champion
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


 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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