Forum Discussion
Getting date difference based on selected date
Hi,
I have a dataset that contains Order Date,Region,Account Number.
Order Date has Data from 1/1/2014 to 31/12/2018.
user want to pass a date value may be through slicer/parameter possibly. ex: 15/07/2015.
Date slicer/parameter should have list of values from 1/1/2014 to 31/12/2018.
based on the date selected by user(Slicer/parameter) which is 15/07/2015, I want to see the date difference b/w Selected Date (15/07/2015) and Order Date (1/1/2014 to 31/12/2018).
No of days = Datediff(order date,selected date,day).
see the below picture for example,
Can anyone help me on this. A quick help would be much appreciated.
5 Replies
- AnonymousNot applicable
Hi,
Below is link to the pbix that i have created for your requirement.
https://1drv.ms/u/s!AikPceQOhqFEhAbLj-X997B3_3gC?e=EzSlwV
Thanks.
- v-lili6-msftCommunity Support
hi, Anonymous
You could get it as below:
Step1:
Create another date table for Date slicer/parameter.
eg. new table
Date = CALENDARAUTO()Step2:selected date= SELECTEDVALUE( Date[Date] )Step3:No of days =
DATEDIFF ( CALCULATE ( MAX ( Table[Order Date] ) ), [Selected Date], DAY )Then just drag Order date filed and these two measure into a table visualBest Regards,Lin- AnonymousNot applicable
Hi,
Thanks for the calculation.
I have got the No of days days b/w selected date & order date.
but the No of days is the measure where I won't be able to get Average of number of days.
because once I get the No of days I need to calculate average of number of days which is not happening.
we can get average of No of days if No of days is column instead of measure. but I try to create No of days as column it's giving me blank data.
Is there anyway that we can get Average of No of Days per Region(or any dimension).
Note: It's an important requiremnet for me to get Average of Numbe of days, almost 15 dashbaord using the same metric.
A quick help would be much appreciated.
Regards
Harsha
- v-lili6-msftCommunity Support
hi, Anonymous
This looks like a measure totals problem. Very common. See this post about it
https://community.powerbi.com/t5/DAX-Commands-and-Tips/Dealing-with-Measure-Totals/td-p/63376Also, this Quick Measure, Measure Totals, The Final Word should get you what you need:
https://community.powerbi.com/t5/Quick-Measures-Gallery/Measure-Totals-The-Final-Word/m-p/547907For your case, you just need to change SUMX to AVERAGEX, you could try this formula:
Measure = VAR _table = ADDCOLUMNS ( 'Table', "_selected date", [selected date], "_no of days", [No of days] ) RETURN AVERAGEX ( FILTER ( _table, [Order Date] <= [_selected date] ), [_no of days] )Result:
and here is my sample pbix file, please try it.
Best Regards,
Lin