Forum Discussion
Bar Chart / Date Calculation
- 8 years ago
Thanks v-juanli-msft
There is a more elegant solution by Marco Russo.
Step 1:- Create a new DateSelection table, this table will be placed on the slicer
DateSelection = DISTINCT ( 'Date'[Calendar WeekNumber] )
Step 2:- Create the measure
Last 4 Week Sales = VAR LastWeek = SELECTEDVALUE ( 'DateSelection'[Calendar WeekNumber] ) VAR FirstWeek = LastWeek - 3 VAR Result = CALCULATE ( SUM ( 'Sales'[Sales] ), KEEPFILTERS ( 'Date'[Calendar WeekNumber] >= FirstWeek && 'Date'[Calendar WeekNumber] <= LastWeek ) ) RETURN ResultStep 3:- Create the bar chart, by placing Date[Calendar WeekNumber] on the axis and [Last 4 Week Sales] on the values.
So, now for any week selected, the bar chart will show 4 bars, one bar for the selected week and 3 previous week.
Hi,
Share the link from where i can download your PBI file.
Couple points...
1) Datesbetween needs a date column Not a weeknumber. Also read this about Dates in PBI (why you are getting nothing)
2) But even if you use a date column using 28 (or 4 weeks times 7 days) will not give you 4 complete weeks but rather 28 consecutive days which is not the same.
Stick with the Marco Russo solution! :smileyhappy: