Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.
Need urgent help on DAX - Rolling 5 weeks from selected fiscal relative week and for last two years
Hello,
I have a sales data which contains fiscal week, Fiscal week Relative, fiscal year, fiscal year relative,total sales...
I have one scliers which contains Fiscal week Relative. Data is for fiscal year (Feb to Feb).
Suppose I have selected -10 as my relative week from sclier. Now I want to see total sales for last rolling 5 weeks.
And I want to show this is in line chart for last 2 Years (2023 and 2022 in legend).
Need to see week 13,12, 11,10 and 9 in x-axis and sales on Y axis.
Attached image of data and output as example.
I hope this message finds you well. I've noticed that this solution remain unresolved. If any of you have managed to find a resolution to the issue, I kindly request that you share your solution for the benefit of the entire community. Alternatively, if you're still facing challenges, please do let us know as well.
Your insights and updates will greatly assist others who might be encountering the same challenge.
To achieve this, you'll need to create a DAX measure that calculates the total sales for the last rolling 5 weeks based on the selected fiscal week relative. Then, you'll use this measure in your line chart to visualize the data for the last two years.
Here's a step-by-step guide:
1. Create a Measure for Total Sales for the Last Rolling 5 Weeks:
Rolling 5 Weeks Sales =
VAR SelectedWeekRelative = SELECTEDVALUE('Table'[Fiscal Week Relative])
VAR MinWeek = SelectedWeekRelative - 4
VAR MaxWeek = SelectedWeekRelative
RETURN
SUMX(
FILTER(
'Table',
'Table'[Fiscal Week Relative] >= MinWeek && 'Table'[Fiscal Week Relative] <= MaxWeek
),
'Table'[Total Sales]
)
2. Create a Line Chart:
- Drag the `Fiscal Week Number` to the X-axis.
- Drag the new `Rolling 5 Weeks Sales` measure to the Y-axis.
- Drag the `Fiscal Year` to the Legend.
3. Filter the Chart:
To ensure that the chart only shows the last 2 years, you can apply a visual-level filter:
- Filter the `Fiscal Year` column to only include the last two years (2023 and 2022).
4. Adjust the X-axis:
To make sure the X-axis only shows the last rolling 5 weeks, you can adjust the X-axis settings:
- Set the minimum value to `SelectedWeekRelative - 4` and the maximum value to `SelectedWeekRelative`.
5. Finalize the Chart:
- Adjust the title, labels, and other formatting options as needed.
Once you've set up the chart, when you select a value from the slicer (e.g., -10), the chart should update to show the total sales for the last rolling 5 weeks for both 2022 and 2023.
The provided DAX code assumes that your table's name is 'Table'. Adjust the table name in the code if it's different.
Hello Thank you for your response.
I am able to get last 4 weeks total on line chart, but it is showing only for one year.
Please suggest how can I add fiscal year two lines so I can compare.
I have tried your solution and able to get weeks but not years.
It will be helpful if you provide solution in pbix.
I have implement your solution in pbix (please find attached pbix).
It is showing only for one week not for rolling 4 weeks and for rolling 2 years.
User | Count |
---|---|
57 | |
22 | |
18 | |
16 | |
11 |
User | Count |
---|---|
85 | |
54 | |
39 | |
21 | |
18 |