Check your eligibility for this 50% exam voucher offer and join us for free live learning sessions to get prepared for Exam DP-700.
Get StartedDon't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.
Good morning
I have a code that utilizes 'addcolumns' to create custom time periods in an easily accessible way and is accessed using a slicer.
An example of the code is displayed at the end bottom of the post.
Currently, I have a line graph that displays data with the x axis being a date range which is filtered using a slicer.
This works in a fairly standard way and works well.
If a user selects, "last 7 days" then the last 7 days of data is displayed.
This is replicated for selections like 'last 14 days', mtd, qtd, last qtr, ytd, last year.
What I now need is if a user selects 'last 7 days' the graph continues to display the last 7 days, then a second graph displays the previous 7 days before that. That methodology is selected for the other time ranges too. Given the nature of the data being displayed, this would provide an easier way to compare performance.
How would I adapt my code to accommodate this?
here is the code of the 'date periods' selection I use.
I look forward to any assistance
Solved! Go to Solution.
HI @MyWeeLola,
In fact, you not need to create a new table. The switch function are used to confirm the period duration which will be used in the calculate expressions.
For example:
The MTD the period duration is month, the YTD is year, QTD is quarter.
For above scenario, you can add a variable with switch function to convert them to days, then you can use this as condition in expressions.
Regards,
Xiaoxin Sheng
HI @MyWeeLola ,
You may need to create a measure formula with switch function to check the current date period type and redirect to the specific formula to show the previous period values.(each period has its own previous calculation expressions)
Write Conditional Statement Using SWITCH in DAX and Power BI - RADACAD
Regards,
Xiaoxin Sheng
Thank you for the response.
Would the following work in principle?
On the result of the switch statement, I could set a min and max date. I would then either create or filter a second date table based on those values, and then apply at date range to the second graph.
What would bite me using that methodology?
Lola
HI @MyWeeLola,
In fact, you not need to create a new table. The switch function are used to confirm the period duration which will be used in the calculate expressions.
For example:
The MTD the period duration is month, the YTD is year, QTD is quarter.
For above scenario, you can add a variable with switch function to convert them to days, then you can use this as condition in expressions.
Regards,
Xiaoxin Sheng
Thank you for the response. I got it working with the second table. That you for your time. It is appreciated.
Lola
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.
Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.
User | Count |
---|---|
21 | |
15 | |
14 | |
11 | |
7 |
User | Count |
---|---|
25 | |
24 | |
12 | |
12 | |
11 |