Forum Discussion
Issue combining VAR and CALCULATE( ..., FILTER
- 8 years ago
Hi AbbasAsaria90,
For your measure, if your CurrentDate variable is simply equal to the dates in the date column then you can simply write your formula as
Leads created, last 28 days = COUNT ( pd_nb_leads[Deals] )
because hen you place your Date colum and the Leads Created, day measure inside the table, the value that is being returned by the measure is being filtered by the value in the Date column.
Now for your second measure, the same thing happens. It is being filtered by the value from the Date column. Thus your seeing the same result. To achieve your desired result, you need to create a separate Calendar table and then create a relationship between the generated date column from Calendar and Date column from your fact table. You can create in a calculated calendar table in dax by using CALENDAR FUNCTION. Example:
CALENDAR = CALENDAR ( MIN ( 'X Axis: Day Created'[Date].DATE ), MAX ( 'X Axis: Day Created'[Date].DATE ) )which is dynamically created based on the earliest and latest dates from Fact. Now, create another measure
Leads created, last 28 days = CALCULATE ( COUNT ( pd_nb_leads[Deals] ), DATESINPERIOD ( Calendar[Date], LASTDATE ( Calendar[Date] ), -28, DAY ) )Put this measure and the date table from calendar to a table.
You can find a good tutorial here: https://powerpivotpro.com/2013/07/moving-averages-sums-etc/
Thanks! I'll take a look at the tutorial and let you know how I get on :)
Thanks, this works for the specific example given :)
Best,
Abbas