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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
venkata
Regular Visitor

Need some help with DAX

I am getting below error.

 

Error Message:
MdxScript(Model) (11, 118) Calculation error in measure 'StationList'[Measure]: Function 'SWITCH' does not support comparing values of type Text with values of type Integer. Consider using the VALUE or FORMAT function to convert one of the values.

 

I am using below formulae:

 

Measure = VAR SelectedGross = CALCULATE ([StnGross], INTERSECT ( VALUES ( Gross[STATION] ), VALUES ( StationList[STATION] ) ))
VAR UnSelectedGross = CALCULATE ( [StnGross], EXCEPT (ALL ( Gross[STATION] ), VALUES ( StationList[STATION] ) ) )
VAR AllGross = CALCULATE ( [StnGross], ALL ( 'Gross'[STATION] ) )
RETURN IF ( HASONEVALUE ( StationList[STATION] ), SWITCH ( VALUES ( StationList[STATION] ), "OTHER", SelectedGross , UnSelectedGross, AllGross))

4 REPLIES 4
v-yulgu-msft
Microsoft Employee
Microsoft Employee

Hi @venkata,

 

It looks like that the SWITCH function in above measure formula doesn't meet the correct syntax.

SWITCH(<expression>, <value>, <result>[, <value>, <result>]…[, <else>])

 

The <expression> should return a single scalar value, where the expression is to be evaluated multiple times (for each row/context). However, in your scenario, VALUES ( StationList[STATION] ) returns a one-column table that contains the distinct values.

 

Also, your purpose is that if result of <expression> equals "OTHER", then return SelectedGross, but how about UnSelectedGross and AllGross? What are their corresponding values?

 

Regards,

Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
mattbrice
Solution Sage
Solution Sage

Is StationList{STATION] a number or text?  Either way, it is trying to compare it to "OTHER" (which is text) or to 'UnSelectedGross' which i assume is an integer.  This is not allowed.  All comparisons must be one or the other.

It is a text

venkata
Regular Visitor

 

Error Message:
MdxScript(Model) (11, 118) Calculation error in measure 'StationList'[Measure]: Function 'SWITCH' does not support comparing values of type Text with values of type Integer. Consider using the VALUE or FORMAT function to convert one of the values.

 

 

Power BI Formulas:


section Section1;

shared Gross = let
Source = Excel.Workbook(File.Contents("C:\Users\mani\Desktop\MS Power BI (2018)\Station Summarized.xlsx"), null, true),
Sheet1_Sheet = Source{[Item="Sheet1",Kind="Sheet"]}[Data],
#"Promoted Headers" = Table.PromoteHeaders(Sheet1_Sheet, [PromoteAllScalars=true]),
#"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"STATION", type text}, {"BUDGET", type number}, {"GROSS", type number}})
in
#"Changed Type";

 

Formlae I have used: 

 

Measure = VAR SelectedGross = CALCULATE ([StnGross], INTERSECT ( VALUES ( Gross[STATION] ), VALUES ( StationList[STATION] ) ))
VAR UnSelectedGross = CALCULATE ( [StnGross], EXCEPT (ALL ( Gross[STATION] ), VALUES ( StationList[STATION] ) ) )
VAR AllGross = CALCULATE ( [StnGross], ALL ( 'Gross'[STATION] ) )
RETURN IF ( HASONEVALUE ( StationList[STATION] ), SWITCH ( VALUES ( StationList[STATION] ), "OTHER", SelectedGross , UnSelectedGross, AllGross))

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors