Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
klehar
Helper V
Helper V

Combining measures into a switch statement

Hi,

 

I'm trying to combine some measures using a switch statement in a calculated column but I get this error

klehar_0-1633001476355.png

 

Here is my dax

 

 

Forecast Actual = 

VAR Total_Upside =
    CALCULATE (
        [Total Value],
        'Table1'[Forecast Category] IN { "Upside" }
    )
VAR Total_Won =
    CALCULATE (
        [Total Value],
        'Table1'[Forecast Category] IN { "Won" }
    )
VAR Total_Commit =
    CALCULATE (
        [Total Value],
        'Table1'[Forecast Category] IN { "Commit" }
    )
RETURN
    SWITCH (
        TRUE (),
        "Commit", Total_Commit,
        "Won", Total_Won,
        "Upside", Total_Upside,
        "Unforecasted"
    )

 

 

How can i resolve this?

I want to use the above created calculated column on my legend shelf of bar chart

7 REPLIES 7
Anonymous
Not applicable

@klehar You should replace in SWITCH function texts ("commit", "won" etc.) with conditions (equal, greater than etc.), that is SWITCH(TRUE(), 'something'="Commit", Total_Comit, 'something_else'="Won", Total_Won, ....)

Im already handling boolean logic in variables. hence i thought this would work

Anonymous
Not applicable

If you check in SWITCH function whether value is equal to TRUE() (expression as the first parameter) then that value have to be boolean.

So what can i do to make this into an expression or combine the above measures into a switch statement

Anonymous
Not applicable

Try this:

 

Forecast Actual=
SWITCH(TRUE(),
	'Table1'[Forecast Category] IN {"Upside"},
	CALCULATE(
             [Total Value],
             'Table1'[Forecast Category] IN {"Upside"}
        ),
	'Table1'[Forecast Category] IN {"Won"},
	CALCULATE(
             [Total Value],
             'Table1'[Forecast Category] IN {"Won"}
        ),
	'Table1'[Forecast Category] IN {"Comit"},
	CALCULATE(
             [Total Value],
             'Table1'[Forecast Category] IN {"Comit"}
        ),
        "Unforcasted"
)

 

It gives me the following error

klehar_0-1633332333871.png

 

Anonymous
Not applicable

 

 

Forecast Actual=
IF(HASONEVALUE('Table1'[Forecast Category]),
SWITCH(TRUE(),
	VALUES('Table1'[Forecast Category]) IN {"Upside"},
	CALCULATE(
             [Total Value],
             'Table1'[Forecast Category] IN {"Upside"}
        ),
	VALUES('Table1'[Forecast Category]) IN {"Won"},
	CALCULATE(
             [Total Value],
             'Table1'[Forecast Category] IN {"Won"}
        ),
	VALUES('Table1'[Forecast Category]) IN {"Commit"},
	CALCULATE(
             [Total Value],
             'Table1'[Forecast Category] IN {"Commit"}
        ),
        "Unforcasted"
))

 

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.