Forum Discussion
SWITCH function in measure returns wrong value in YTD calculation group
- 1 year ago
Hi Anonymous ,
I have done the following:
- Created a new column on the Wins forecast table:
Category Adjusted = var _Category = SWITCH( TRUE(), MONTH([date_month]) <= 6 && MONTH([date_month]) > 3, "BUD", MONTH([date_month]) <= 9 && MONTH([date_month]) > 6, "3+9", MONTH([date_month]) <= 12 && MONTH([date_month]) > 9, "6+6" ) RETURN IF (_Category = 'Wins forecast'[category], _Category)Add this new measure:
Wins FC NEW MEASURE = CALCULATE(SUM('Wins forecast'[wins]),'Wins forecast'[Category Adjusted] <> "")This will allow to have the calculation of the forecast without the need for the switch measure, you can see that the result will be correct based on the selection:
See file attach.
This setup forces the values to show up only for the specific moths were each forecast is used and not on the rest of the year where the values are for budget or for other forecast.
I did the new column in DAX but you can also do it in M Query that is more advisable.
MFelix, thank you so much for your time and effort! The YTD and variance work as they should now. I have only changed the VAR currentmonth to month(max(Dim_date[Date])) instead of month(selectedvalue (Dim_date[Date])) from my initial approach and it works like a charm.
For others looking for Budget and Forecast inspiration; my approach or MFelix approach works just fine depending on your use-case.