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.
I don't see any bars on the chart. No matter what week I select.
Here is my data model: The 'DateSelection' table is not used in your calculated measure and Calculations table is just me storing the measures. There is a 1-Many relationship between Sales and Date table
And here is the measure:
Any ideas why this doesn't work?
Hi,
The relationship should be from the Order Date column of the Sales Table to the Date column of the Date Table.
- shivkonar8 years agoFrequent Visitor
- Ashish_Mathur8 years agoSuper User
Hi,
Share the link from where i can download your PBI file.
- Sean8 years agoCommunity Champion
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: