Forum Discussion
Rolling Snapshot Line Chart
- 4 years ago
Anonymous
Hopefully I am understanding you correctly.
You want to see a line chart for the last 13 weeks, but you want to see the X-axis data points grouped by week (rather than the day)?
If so, then you can take the following steps.
1) Add the Calculated Column "Week Date Starting Monday" to the Invoice Table.
- NOTE: DATEADD had to be replaced by DATE because DATEADD will return blank rows if the date does not exist in the source column - not cool, but that's DAX.2) In the new line chart visual X-axis value, replace [Transaction_Date] with the new calculated column [Week Date Starting Monday]. Now all the data will be grouped by week.
- NOTE: You still need the "In Last 13 Weeks" filter on the page or visual as mentioned in the previous post.My apologies if I misunderstood your question.
If this is not what you are looking for, could you provide a simple mock-up in Excel to help me understand better?
Regards,
Nathan
- 4 years ago
Anonymous
Hello Ian,
Foolish mistake on my part. Very sorry about that.
There is nothing wrong with your data. My limited data just accidentally worked because I have no dates in the first few days of any month.
My code is flat wrong because I'm subtracting: DAY - WEEKDAY. (Digit - Digit)
- DAY is just the number of the day in the month. It has no month or year context.
- IF DAY = 1 (1st of the month) & I subtract any number THEN we'll get a negative DAY number, which cannot be a valid DAY of any month, and therefore throws the error.
To write the code correctly, we need to subtract WEEKDAY from the entire DATE. In this way, the problem is resolved:
OLD CODE: 1 - 4 = -3 (A negative DAY can never be part of a valid date.)
NEW CODE 7/1/2022 - 3 = 6/27/2022 (This results in a valid date.)
Hopefully this explanation helps you to understand my logical error.
Regards,
Nathan
Anonymous
Additional Notes:
- Calculated Columns are only re-calculated on refresh.
- As long as you have the report set to auto-refresh daily, the rolling time-frame will function properly.
For example, I refreshed the report this morning, and can now see that 7/21/2022 is correctly included in both Line Charts for today.
Regards,
Nathan
Thank you, this is definitely a helpful starting point. I do have a few extra notes.
Doing it this way is rolling forward by day. What if I wanted it to only shift one business week at a time? Let's say I consider my week as Monday- Sunday. When Monday comes along, we want the chart to show the dates for that Monday all the way through Sunday.
My next question is if I want to Sum by Week. And have the rolling shift Monthly.
Regards,
Ian