Forum Discussion
shivkonar
8 years agoFrequent Visitor
Bar Chart / Date Calculation
Hi, I am trying to solve a made up problem. Imagine we have a 2 table model. The Sales table and a Date Table in a 1 to Many relationship. On the Power BI report, there is a slicer for Date[C...
- 7 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.
shivkonar
7 years agoFrequent Visitor
Here you go:- https://drive.google.com/drive/folders/19Qw-n4gV4ncsffU-PV58_PUI8PgmlRLu?usp=sharing
Page 1 is Marco's solution
Page 2 and [Last 4 Week Sales5] are your solution.
Ashish_Mathur
7 years agoSuper User
Hi,
I am unable to solve the problem with my formula. I believe you should stick to Marco's solution.