Forum Discussion

ExcelMonke's avatar
ExcelMonke
Impactful Individual
2 years ago

Switch result not as expected

Hello,

I am trying to create a new table based on the formula below. Ultimately, this table is a bridge within my data model in order for me to be able to create a "smart axis" for a chart - all credit for this goes to: How to Power BI on Youtube.

The problem I am running into is that my Variable OR Switch function (not sure which) is not returning the intended result. I created a standalone measure to validate the Variable, and it is returning the correct intended result. Regardless of how I filter the dates, my period column will always return "4". I have tried to troubleshoot and am not able to come to solution.

 

 

DateToPeriodBridge = 
ADDCOLUMNS(
    CALENDAR(MIN(Table[OrderDate]),MAX(Table[OrderDate])),
    "Period",
    VAR MonthCount = DATEDIFF(MIN(DateDim[FullDate]),[Date],MONTH)
    RETURN
    SWITCH(
        TRUE(),
        MonthCount = 0, 0, -- Date break
        MonthCount <= 2, 1, -- Week
        MonthCount <= 3, 2, -- Month
        MonthCount <= 12, 3, -- Quarter
        4 --Year
    )
)

 

 

 

2 Replies