Forum Discussion
Weekly variance calculations with year change
- 3 years ago
Hi DomantasK ,
Are you trying to calculate current week's value minus previous week's value? If it is like this, please try following steps.
This is my test table:
I suggest you trying to create new columns instead of measures.
Current_week_value = var Current_date = MINX(FILTER('Table','Table'[Week] = EARLIER('Table'[Week]) && 'Table'[Year] = EARLIER('Table'[Year])),'Table'[Date]) return IF('Table'[Date] = Current_date, CALCULATE(SUM('Table'[Value]),FILTER('Table','Table'[Year] = EARLIER('Table'[Year]) && 'Table'[Week] = EARLIER('Table'[Week]))) ) Previous_week_value = var Current_date = MINX(FILTER('Table','Table'[Week] = EARLIER('Table'[Week]) && 'Table'[Year] = EARLIER('Table'[Year])),'Table'[Date]) return IF('Table'[Date] = Current_date, CALCULATE(SUM('Table'[Value]),FILTER('Table','Table'[Week] = EARLIER('Table'[Week]) - 1 && 'Table'[Year] = EARLIER('Table'[Year]))) ) Last week variance = var Final_week_2021 = CALCULATE(SUM('Table'[Value]), FILTER('Table','Table'[Year] = 2021 && 'Table'[Week] = MAX('Table'[Week]))) var Current_date = MINX(FILTER('Table','Table'[Week] = EARLIER('Table'[Week]) && 'Table'[Year] = EARLIER('Table'[Year])),'Table'[Date]) return SWITCH( TRUE(), 'Table'[Year] = 2021 && 'Table'[Week] = MIN('Table'[Week]) && 'Table'[Date] = Current_date, 0, 'Table'[Year] = 2022 && 'Table'[Week] = MIN('Table'[Week]) && 'Table'[Date] = Current_date, ABS([Current_week_value] - Final_week_2021), 'Table'[Date] = Current_date, ABS([Current_week_value]-[Previous_week_value]) )Variance for 2021 01 is 0.
Variance for 2022 01 is 2022 01 - 2021 53.
I think this is the result you want:
Best regards,
Yadong Fang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi DomantasK ,
Due to the inconsistency of our models, in order to better understanding your demands and give the right solution, could you please share with me some screenshots of your data after hiding sensitive information.
Best regards,
Yadong Fang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.