Forum Discussion

GijsBI's avatar
GijsBI
Icon for Helper II rankHelper II
1 year ago

Incorrect period over period change when using dateadd

Hi, 

 

I'm trying to calculate the change between different periods (weeks, months, etc.) which are selected by the user with a field parameter. I noticed I get some strange results when I try to use dateadd to calculate last week's results when the week is around the new year / end of the prior year.  Since parallelperiod only works for Months and longer, what could I do to overcome this problem?

 

Code: 

_count last period =
VAR _maxdate = max(dim_date[Date])
VAR __SelectedValue =
    SELECTCOLUMNS (
        SUMMARIZE ( prmDates, prmDates[prmDates], prmDates[prmDates Fields] ),
        prmDates[prmDates]
    )
RETURN
SWITCH(
    TRUE,
    __SelectedValue= "Year-week", CALCULATE(sum(fct_counters[counter]), dateadd(dim_date[Date], -7, DAY)))

2 Replies