Forum Discussion
Switch between 'Year to Date' and 'Week to Date'
- Anonymous2 years ago
Hi Anonymous ,
According to your statement, I think you want to calculate the number of previous week and the number of 2nd previous week based on the last date in your slicer.
Here I suggest you to try code as below. My Sample is easy a Data table with two columns [Date] and [Number] and a Calendar Table with date from 2023/08/28 to today.
Previous Month Number = VAR _MAXDATE = MAX('Calendar'[Date]) VAR _PREVIOUSWEEKEND = _MAXDATE - WEEKDAY(_MAXDATE,2) VAR _PREVIOUSWEEKSTART = _PREVIOUSWEEKEND - 6 RETURN CALCULATE(SUM('Table'[Number]),FILTER(ALL('Calendar'),'Calendar'[Date]>=_PREVIOUSWEEKSTART && 'Calendar'[Date]<=_PREVIOUSWEEKEND))2nd Previous Month Number = VAR _MAXDATE = MAX('Calendar'[Date]) VAR _PREVIOUSWEEKEND = _MAXDATE - WEEKDAY(_MAXDATE,2) VAR _2NDPREVIOUSWEEKEND = _PREVIOUSWEEKEND - 7 VAR _2NDPREVIOUSSTART = _2NDPREVIOUSWEEKEND - 6 RETURN CALCULATE(SUM('Table'[Number]),FILTER(ALL('Calendar'),'Calendar'[Date]>=_2NDPREVIOUSSTART && 'Calendar'[Date]<=_2NDPREVIOUSWEEKEND))Difference = [Previous Month Number] - [2nd Previous Month Number]Difference% = DIVIDE([Difference],[2nd Previous Month Number])Result is as below.
If this reply still couldn't help you solve your issue, please share a sample file with us.
Best Regards,
Rico ZhouIf this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi Anonymous ,
According to your statement, I think you want to calculate the number of previous week and the number of 2nd previous week based on the last date in your slicer.
Here I suggest you to try code as below. My Sample is easy a Data table with two columns [Date] and [Number] and a Calendar Table with date from 2023/08/28 to today.
Previous Month Number =
VAR _MAXDATE = MAX('Calendar'[Date])
VAR _PREVIOUSWEEKEND = _MAXDATE - WEEKDAY(_MAXDATE,2)
VAR _PREVIOUSWEEKSTART = _PREVIOUSWEEKEND - 6
RETURN
CALCULATE(SUM('Table'[Number]),FILTER(ALL('Calendar'),'Calendar'[Date]>=_PREVIOUSWEEKSTART && 'Calendar'[Date]<=_PREVIOUSWEEKEND))2nd Previous Month Number =
VAR _MAXDATE = MAX('Calendar'[Date])
VAR _PREVIOUSWEEKEND = _MAXDATE - WEEKDAY(_MAXDATE,2)
VAR _2NDPREVIOUSWEEKEND = _PREVIOUSWEEKEND - 7
VAR _2NDPREVIOUSSTART = _2NDPREVIOUSWEEKEND - 6
RETURN
CALCULATE(SUM('Table'[Number]),FILTER(ALL('Calendar'),'Calendar'[Date]>=_2NDPREVIOUSSTART && 'Calendar'[Date]<=_2NDPREVIOUSWEEKEND))Difference = [Previous Month Number] - [2nd Previous Month Number]Difference% = DIVIDE([Difference],[2nd Previous Month Number])
Result is as below.
If this reply still couldn't help you solve your issue, please share a sample file with us.
Best Regards,
Rico Zhou
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.