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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
AshDil
Helper V
Helper V

Want to calculate difference between dates entered in Slicer even those records not present in Table

Hi,

I have the date range slicer as follows,

AshDil_0-1638243416264.png

In date slicer I have selected Start date = 5/1/2017 and End date  = 3/16/2018. As these dates are not present in my fact table I'm getting difference as blank.

Please help me to do it.

Thanks,

AshDil.

1 ACCEPTED SOLUTION

Hi @AshDil 

If you want to calculate the day differences by dates in your date between slicer, you need to use min and max function to catch the start date and the end date in your data model. So you need to create a date table by dax, and relate two tables by date column, then create slicer by date column in date table.

Date Table:

Date = CALENDARAUTO()

Relationship:

1.png

Measure:

DayDiff = 
VAR _RangeStart = MIN('Date'[Date])
VAR _RangeEnd = MAX('Date'[Date])
RETURN
DATEDIFF(_RangeStart,_RangeEnd,DAY)

Result is as below.

2.png

Best Regards,
Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
amitchandak
Super User
Super User

@AshDil , Ideally you should use a date table wih all the needed dates and join that with you table

 

measure =
var _max = maxx(allselected('Date'),'Date'[Date])
var _min = minx(allselected('Date'),'Date'[Date])
return

datediff(_min, _max, day)

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Hi @amitchandak ,

 

I have tried using above formula but getting large difference.

For eg, I have selected Start date = 11/22/2021 and End Date = 11/30/2021 my expected output is 8, but getting difference as 1461.

Please help me do it.

Thanks,

Ashdil

Hi @AshDil 

If you want to calculate the day differences by dates in your date between slicer, you need to use min and max function to catch the start date and the end date in your data model. So you need to create a date table by dax, and relate two tables by date column, then create slicer by date column in date table.

Date Table:

Date = CALENDARAUTO()

Relationship:

1.png

Measure:

DayDiff = 
VAR _RangeStart = MIN('Date'[Date])
VAR _RangeEnd = MAX('Date'[Date])
RETURN
DATEDIFF(_RangeStart,_RangeEnd,DAY)

Result is as below.

2.png

Best Regards,
Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

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! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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