Forum Discussion
Measure with Date from Slicer
Hi,
I have a date slicer where the user can select start and end dates.
I'm trying to capture the difference between those 2 dates to see the number of days the user is selecting, but any formula that I thought to use capture the start or end dates in the dataset. Meaning if my start date in the slicer is Jan 1st, but my data only starts at Jan 2nd, the result would be Jan 2nd.
The only othe solution I thought was to create another support table with a basic calendar dates...but seems to much just for this.
Any idea how to do this with a measure instead of craeting a new table?
Thank you
Hi Anonymous
Create measures
startdate = MIN('Table'[Date]) enddate = MAX('Table'[Date]) day diff = DATEDIFF([startdate],[enddate],DAY)+1Best Regards
Maggie
Community Support Team _ Maggie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
6 Replies
- parry2k
Super User
Anonymous you should create two variables in a measure to get firstnonblank and lastnonblank based on the dates selected by the user and from those variables calculate the number of days.
I would ❤ Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos whoever helped to solve your problem. It is a token of appreciation!
⚡Visit us at https://perytus.com, your one-stop shop for Power BI related projects/training/consultancy.⚡
- AnonymousNot applicable
Hi parry2k ,
Thanks for the answer, but firstnonblank would bring the first value in my dataset, even if the selected value in the slicer is before that. I need exactly what the user selected in the slicer.- Tahreem24
Super User
Utilise the SelectedValue dax to capture the user selection.
- lbendlin
Super User
You're on the right track. Having a separate dates table is ALWAYS worth the effort.
- v-juanli-msft
Community Support
Hi Anonymous
Create measures
startdate = MIN('Table'[Date]) enddate = MAX('Table'[Date]) day diff = DATEDIFF([startdate],[enddate],DAY)+1Best Regards
Maggie
Community Support Team _ Maggie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.