Reply
gill_thornton
Helper I
Helper I
Partially syndicated - Outbound

Measure using switch giving error on visual

Please can someone help with the following.  I have a measure:

ontext = SWITCH(TRUE(),
                    SELECTEDVALUE(Context[Gender])="M","Boys",
                    SELECTEDVALUE(Context[Gender])="F","Girls",
                    SELECTEDVALUE(Context[EAL]) = "Unknown","Unclassified EAL",
                    SELECTEDVALUE(Context[EAL]) = "No","English",
                    SELECTEDVALUE(Context[EAL]) = "Yes","Other than English",
                    SELECTEDVALUE(Context[Ethnicity])="Any other Asian background","Asian - Any other Asian background",
                    SELECTEDVALUE(Context[Ethnicity])="Any other Black background","Black - Any other Black background",
                    SELECTEDVALUE(Context[Ethnicity])="Any other ethnic group","Other - Any other ethnic group",
                    SELECTEDVALUE(Context[Ethnicity])="Any other mixed background","Mixed - Any other mixed background",
                    SELECTEDVALUE(Context[Ethnicity])="Any other White background","White - Any other White background",
                    SELECTEDVALUE(Context[Ethnicity])="Bangladeshi","Asian - Bangladeshi",
                    SELECTEDVALUE(Context[Ethnicity])="Black African","Black - Black African",
                    SELECTEDVALUE(Context[Ethnicity])="Black Caribbean","Black - Caribbean",
                    SELECTEDVALUE(Context[Ethnicity])="Chinese","Chinese Total",
                    SELECTEDVALUE(Context[Ethnicity])="Indian","Asian - Indian",
                    SELECTEDVALUE(Context[Ethnicity])="Information Not Yet Obtained","Unclassified - Total",
                    SELECTEDVALUE(Context[Ethnicity])="Pakistani","Asian - Pakistani",
                    SELECTEDVALUE(Context[Ethnicity])="Refused","Unclassified - Total",
                    SELECTEDVALUE(Context[Ethnicity])="Traveller of Irish heritage","White - Traveller of Irish heritage",
                    SELECTEDVALUE(Context[Ethnicity])="White - British","White - White British",
                    SELECTEDVALUE(Context[Ethnicity])="White and Asian","Mixed - White and Asian",
                    SELECTEDVALUE(Context[Ethnicity])="White and Black African","Mixed - White and Black African",
                    SELECTEDVALUE(Context[Ethnicity])="White and Black Caribbean","Mixed - White and Black Caribbean",
                    OR(SELECTEDVALUE(Context[Ethnicity])="White - Irish",SELECTEDVALUE(Context[Ethnicity])="White - Northern Irish"),"White - White Irish",
                    OR(SELECTEDVALUE(Context[Ethnicity])="Other Gypsy/Roma",SELECTEDVALUE(Context[Ethnicity])="Any other ethnic group"),"Other - Any other ethnic group",
                    OR(SELECTEDVALUE(Context[Ethnicity])="Gypsy",SELECTEDVALUE(Context[Ethnicity])="Gypsy/Roma"),"White - Gypsy/Roma",
                    SELECTEDVALUE(Context[Pupil Premium Indicator]) ="T","Disadvantaged",
                    SELECTEDVALUE(Context[Pupil Premium Indicator]) ="F","Disadvantaged all other",
                    SELECTEDVALUE(Context[SEN Code])="E","SEN State EHC",
                    SELECTEDVALUE(Context[SEN Code])="K","SEN Supp",
                    SELECTEDVALUE(Context[SEN Code])="N","No SEN",
                    "Total")
 
This is causing an error in the visual - 'Calculation error in measure ...cannot convert value 'Total' of type text to type true/false'
 
Any help with this issue would be much apprecitated.  Thank you.
1 ACCEPTED SOLUTION
gill_thornton
Helper I
Helper I

Syndicated - Outbound

Thank you for taking the time to look at the issue.  I now have a solution for this.

View solution in original post

4 REPLIES 4
gill_thornton
Helper I
Helper I

Syndicated - Outbound

Thank you for taking the time to look at the issue.  I now have a solution for this.

avatar user
Anonymous
Not applicable

Syndicated - Outbound

Hi @gill_thornton ,

The error message you’re seeing indicates that the function in your measure is returning a value of type text instead of a value of type true/false. This is because the last argument of your function is the text string , which is not a valid value for a true/false expression.

ontext = SWITCH(TRUE(),
                    SELECTEDVALUE(Context[Gender])="M","Boys",
                    SELECTEDVALUE(Context[Gender])="F","Girls",
                    SELECTEDVALUE(Context[EAL]) = "Unknown","Unclassified EAL",
                    SELECTEDVALUE(Context[EAL]) = "No","English",
                    SELECTEDVALUE(Context[EAL]) = "Yes","Other than English",
                    SELECTEDVALUE(Context[Ethnicity])="Any other Asian background","Asian - Any other Asian background",
                    SELECTEDVALUE(Context[Ethnicity])="Any other Black background","Black - Any other Black background",
                    SELECTEDVALUE(Context[Ethnicity])="Any other ethnic group","Other - Any other ethnic group",
                    SELECTEDVALUE(Context[Ethnicity])="Any other mixed background","Mixed - Any other mixed background",
                    SELECTEDVALUE(Context[Ethnicity])="Any other White background","White - Any other White background",
                    SELECTEDVALUE(Context[Ethnicity])="Bangladeshi","Asian - Bangladeshi",
                    SELECTEDVALUE(Context[Ethnicity])="Black African","Black - Black African",
                    SELECTEDVALUE(Context[Ethnicity])="Black Caribbean","Black - Caribbean",
                    SELECTEDVALUE(Context[Ethnicity])="Chinese","Chinese Total",
                    SELECTEDVALUE(Context[Ethnicity])="Indian","Asian - Indian",
                    SELECTEDVALUE(Context[Ethnicity])="Information Not Yet Obtained","Unclassified - Total",
                    SELECTEDVALUE(Context[Ethnicity])="Pakistani","Asian - Pakistani",
                    SELECTEDVALUE(Context[Ethnicity])="Refused","Unclassified - Total",
                    SELECTEDVALUE(Context[Ethnicity])="Traveller of Irish heritage","White - Traveller of Irish heritage",
                    SELECTEDVALUE(Context[Ethnicity])="White - British","White - White British",
                    TRUE())

SWITCH function (DAX) - DAX | Microsoft Learn

 

How to Get Your Question Answered Quickly 

 

If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .

 

Best Regards
Community Support Team _ Rongtie

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

 

 

 

Syndicated - Outbound

Thank you.  The national data supplied by the department of education doesn't quite match the context data for our school population.  In the national data there is a value under characteristics of total.  I don't have such a value in my context table.  However, I need total to be shown as "All students".

Uzi2019
Super User
Super User

Syndicated - Outbound

Hi @gill_thornton 
Dont take measure try to take calculated columnfr this type of calculation.

 

Don't forget to give thumbs up and accept this as a solution if it helped you!!!
avatar user

Helpful resources

Announcements
March PBI video - carousel

Power BI Monthly Update - March 2025

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

March2025 Carousel

Fabric Community Update - March 2025

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

Top Solution Authors (Last Month)
Top Kudoed Authors (Last Month)