Starting December 3, join live sessions with database experts and the Microsoft product team to learn just how easy it is to get started
Learn moreGet 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
Hi,
I have the date range slicer as follows,
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.
Solved! Go to 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:
Measure:
DayDiff =
VAR _RangeStart = MIN('Date'[Date])
VAR _RangeEnd = MAX('Date'[Date])
RETURN
DATEDIFF(_RangeStart,_RangeEnd,DAY)
Result is as below.
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.
@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)
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:
Measure:
DayDiff =
VAR _RangeStart = MIN('Date'[Date])
VAR _RangeEnd = MAX('Date'[Date])
RETURN
DATEDIFF(_RangeStart,_RangeEnd,DAY)
Result is as below.
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.
Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.
User | Count |
---|---|
86 | |
76 | |
74 | |
56 | |
45 |
User | Count |
---|---|
117 | |
105 | |
77 | |
66 | |
64 |