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

Get certified as a Fabric Data Engineer: Check your eligibility for a 50% exam voucher offer and join us for free live learning sessions to get prepared for Exam DP-700. Get started

Reply
kris_talikowski
Frequent Visitor

datediff and a slicer

Hi

I have a table Visits with Customer ID (Customer ID FK] and multiple customer visits with visit date (Start Date).

This measure works beautifully when there is no date slicer on the report. It brings number of days between customer's first visit date and today.

CustomerRelationship = SUMMARIZE(Visits,Visits[Customer ID FK], "Relationship",DATEDIFF(min(Visits[Start Date]),TODAY(),DAY))
 

Now, I would like the users to have an option to select a date instead of using Today. I want to calculate first visit's date against selected date on the slicer.

 

This measure works but it always brings the value of 1 because min(Visits[Start Date) is taken from the slicer. So, there is just one day difference (or 0 depending on date format) between min date and selected date.

CustomerRelationship = SUMMARIZE(Visits,Visits[Customer ID FK], "Relationship",CALCULATE(DATEDIFF(min(Visits[Start Date]), SELECTEDVALUE('Date'[Month Year]),DAY)))

 

Any ideas? You help would be appreciated.

2 REPLIES 2
kris_talikowski
Frequent Visitor

Thaanks amitchandak.

I applied this but the message I have now is, the expression specified in the query is not a valid table expression.

CustomerRelationship = AverageX(

SUMMARIZE(Visits,Visits[Customer ID FK], "_Relationship",DATEDIFF(min(Visits[Start Date]),selectedvalue(TableDate[Day Date]),DAY)), [_Relationship])
 
kris_talikowski_0-1704124333679.png

 

amitchandak
Super User
Super User

@kris_talikowski , Create a measure and use that with customer from original table

 

AverageX(

SUMMARIZE(Visits,Visits[Customer ID FK], "_Relationship",DATEDIFF(min(Visits[Start Date]),selectedvalue(Date[Date]),DAY)), [_Relationship])

 

You can use SUMX inplace of Averagex or You can use maxx(allselected(Date), Date[Date])  in place of selectedvalue(Date[Date])

 

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Jan NL Carousel

Fabric Community Update - January 2025

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