Forum Discussion
Reference a previous month using variables in DAX using slicers
Hi Vanessa,
I am trying to get the full previous week rather than just one day
Thanks for helping though...much appreciated.
Chris
Anonymous ag ok make sense, probably need to use week numbers then, perhaps using the function earlier could help? if you had a week number in your date table?
- Anonymous9 years agoNot applicable
Last Week Targets = VAR myMax = MAX('Calendar$'[Weeknum]) RETURN CALCULATE(SUM(internetTargets[Impressions]),ALLEXCEPT(internetTargets,internetTargets[weeknum],joinTable[Website],'Calendar$'[Year],'Calendar$'[Month Name]),internetTargets[weeknum]=myMax-1) - Anonymous9 years agoNot applicable
Yep got a week number in the date table but it doesnt seem to like using the weeknum function within an evaluation
- vanessafvg9 years agoCommunity Champion
Anonymous show me your code?
- vanessafvg9 years agoCommunity Champion
Anonymous will look into later for you
not really sure what you trying to do in that calculation though can you give an explanation before i attempt to rewrite it
- Anonymous9 years agoNot applicable
Sure, basically i am trying to sum the previous weeks values.
That calculation gives this weeks value but when I select a dat near the beginning or end of the month the values dont work. I think it is becasue the slicer sets the table to on the the months selected so the previous week does not work.
- vanessafvg9 years agoCommunity Champion
ok just that your code looks a bit stranger to me i am not sure what you doing
Last Week Targets = VAR myMax = MAX('Calendar$'[Weeknum]) RETURN CALCULATE(SUM(internetTargets[Impressions]),ALLEXCEPT(internetTargets,internetTargets[weeknum],joinTable[Website],'Calendar$'[Year],'Calendar$'[Month Name]),internetTargets[weeknum]=myMax-1)
firstly it looks like you using 2 tables, is the week number in the calendar table?
secondly your relationships between your date table and internettargets is there one?
essentially though you need to be doing a filter something to this effect
Last Week Targets = VAR myMax = MAX('Calendar$'[Weeknum])
RETURN CALCULATE(SUM(internetTargets[Impressions]), filter('Calendar$', 'Calendar$'[Year]' = Year(now()) &
mymax='calendar'[weeknum]-1)
am sure this isn't right but need to know more about how your data is structured
- Anonymous9 years agoNot applicable
Yep
three tables
one contains date
two contains internet page impressions targets
three contains ga page impressions
There is a week num column in each table and 2/3 joins the calendar table via the date column
- Anonymous9 years agoNot applicable
Tried what you suggest but it throws up the error
MdxScript(Model) (9, 73) Calculation error in measure 'GA'[Last Week Targets]: DAX comparison operations do not support comparing values of type Integer with values of type Text. Consider using the VALUE or FORMAT function to convert one of the values.All values are whole numbers.....
After some more testing it seems it does not like the YEAR function