Forum Discussion
Creating a custom Date Slicer
Hi, Anonymous
Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.
Table:
Test:
Calendar(a calculated table):
Calendar = CALENDAR(DATE(2015,1,1),DATE(2020,12,31))
There is no relationship between tables. You may create two measures as below.
DateRange =
var _cam = SELECTEDVALUE('Table'[Marketing Campaign])
return
IF(
ISFILTERED(Test[Marketing Campaign]),
SWITCH(
TRUE(),
"Penetration" in DISTINCT(Test[Marketing Campaign])&&_cam = "Penetration",
"1/1/18 to 5/25/2018",
"BOGO" in DISTINCT(Test[Marketing Campaign])&&_cam = "BOGO",
"5/26/18 to 7/4/18",
"Contracted Deals" in DISTINCT(Test[Marketing Campaign])&&_cam = "Contracted Deals",
"7/5/18 to 10/15/18",
BLANK()
)
)
Visual Control =
var _date = SELECTEDVALUE('Calendar'[Date])
return
IF(
ISFILTERED(Test[Marketing Campaign]),
IF(
HASONEVALUE(Test[Marketing Campaign]),
SWITCH(
SELECTEDVALUE(Test[Marketing Campaign]),
"Penetration",
IF(
_date>=DATE(2018,1,1)&&
_date<=DATE(2018,5,25),
1,0
),
"BOGO",
IF(
_date>=DATE(2018,5,26)&&
_date<=DATE(2018,7,4),
1,0
),
"Contracted Deals",
IF(
_date>=DATE(2018,7,5)&&
_date<=DATE(2018,10,15),
1,0
)
),
0
),
0
)
Finally you need to put 'Visual Control' measure in the corresponding visual level filter to filter out the result.
Best Regards
Allan
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- Anonymous6 years agoNot applicable
Thank you for the help.
I couldn't get it to work until I figured out I needed to create a new table, and write it as a formula.
The solution worked once I figured that part out. I had to add in some dynamic dates and did that by adjusting the date(2020,5,1) to MAX(DATE) in the two DAX formulas.
However when I try to deselect the certain period to see the overall time frame, it doesn't work.
- v-alq-msft6 years agoCommunity Support
Hi, Anonymous
I am not very clear about your requirement. Could you please show us some sample data and expected results with OneDrive for business? Do mask sensitive data before uploading. Thanks.
Best Regards
Allan