Check your eligibility for this 50% exam voucher offer and join us for free live learning sessions to get prepared for Exam DP-700.
Get StartedDon't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.
I'm trying to convert an expression from an old SSRS report to Power BI and running into the following problem. I have a table of Monthly sales figures (Jan, Feb, Mar,...) and the rows contain numerical values representing sales figures for that month.
I am trying to use the following expression but am receiving the error: "Function 'SWITCH' does not support comparing values of type True/False with values of type Number. Consider using the VALUE or FORMAT function to convert one of the values"
I found a few posts on this but I'm still uinsure of how to structure the expression for a new measure.
Monthly Sales =
(switch(Month(Now()) = 1, Sum(Jan_Value),
Month(Now()) = 2, Sum(Feb_Value),
Month(Now()) = 3, Sum(Mar_Value),
Month(Now()) = 4, Sum(Apr_Value),
Month(Now()) = 5, Sum(May_Value),
Month(Now()) = 6, Sum(Jun_Value),
Month(Now()) = 7, Sum(Jul_Value),
Month(Now()) = 8, Sum(Aug_Value),
Month(Now()) = 9, Sum(Sept_Value),
Month(Now()) = 10, Sum(Oct_Value),
Month(Now()) = 11, Sum(Nov_Value),
Month(Now()) = 12, Sum(Dec_Value))/1000)
There is another option
Monthly Sales =
DIVIDE(
switch(Month(Now(),1, Sum(Jan_Value),
2, Sum(Feb_Value),
3, Sum(Mar_Value),
4, Sum(Apr_Value),
5, Sum(May_Value),
6, Sum(Jun_Value),
7, Sum(Jul_Value),
8, Sum(Aug_Value),
9, Sum(Sept_Value),
10, Sum(Oct_Value),
11, Sum(Nov_Value),
12, Sum(Dec_Value))
,1000)
Having values per month in different column is a design red flag.
I was able to get it to work by adding TRUE() before the arguments, so:
Monthly Sales =
(switch(
TRUE(),
Month(Now()) = 1, Sum(Jan_Value),
Month(Now()) = 2, Sum(Feb_Value),
Month(Now()) = 3, Sum(Mar_Value),
Month(Now()) = 4, Sum(Apr_Value),
Month(Now()) = 5, Sum(May_Value),
Month(Now()) = 6, Sum(Jun_Value),
Month(Now()) = 7, Sum(Jul_Value),
Month(Now()) = 8, Sum(Aug_Value),
Month(Now()) = 9, Sum(Sept_Value),
Month(Now()) = 10, Sum(Oct_Value),
Month(Now()) = 11, Sum(Nov_Value),
Month(Now()) = 12, Sum(Dec_Value),
BLANK()
)
I could also drop the /1000 since I can just format the column directly in POWER BI.
Agreed on the data structure, but this was easier than trying to get a programmer to update the source data.
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.
User | Count |
---|---|
97 | |
65 | |
45 | |
39 | |
31 |
User | Count |
---|---|
164 | |
111 | |
61 | |
53 | |
38 |