I am trying to create a parameter/variable/formula to return a given period of time. I have three periods.
I want the user to be able to select a Marketing Campaign Name and the data switches based on the campaign slicer to the dates below.
Penetration: 1/1/18 to 5/25/2018
BOGO: 5/26/18 to 7/4/18
Contracted Deals: 7/5/18 - 10/15/18
I started by making a table with the names of the campaigns.
I included an index, and sorted by the index, so when I add the table values as a card, they appear in the desired order.
After that I don't know how to set up my variables or create measures to use in the switch formula. I don't think I need parameters in this case, but I don't know how to set the date range either way. I'm less than 40 hours into building DAX.
After I have my variables I think I can use Switch(True(),
[Campaign Selected] = "Penetration", [Penetration] ),
[Campaign Selected] = "BOGO", [BOGO] ),
[Campaign Selected] = "Contracted Deals", [Contracted Deals] ),
But I'm going to get caught up again because I don't how to create a time period for the false period which would be 1/1/18 - 10/15/18. I guess another option would be to have four periods with one being the full period.
Appreciate the help!
Has this post solved your problem? Please mark it as a solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos.
I work as a trainer and consultant for Microsoft 365, specialising in Power BI and Power Query.
For your campaigns add two more columns to the reference table. Start Date and End Date.
Then when a campaign is selected you can filter your dates table using DATESBETWEEN() with the selected campaign's dates.
This will then automatically filter your transaction table for that date range.
Note: If you only compare against a single value you can simplify the switch statement like this:
Switch([Campaign Selected],"Penetration", [Penetration],"BOGO", [BOGO],"Contracted Deals", [Contracted Deals] ,or else)
Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.
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.
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Thanks for the help.
I couldn't figure out how to write the datesbetween formula, and I actually have data that goes into dynamic dates. I couldn't figure out how to write into a table MAX(Date) or TODAY(), so I couldn't take this approach.
Appreciate the help though!
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.
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.