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

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.

Reply
Anonymous
Not applicable

SWITCH Function not giving correct result

Hey 🙂 I have a problem with a task and maybe someone here can help me to solve it. I have listed projects and their revenue in the Excel table. Now I want to visualize the data and create a chart using Power BI by dividing projects into category S and C. Category C includes all projects with revenue more than 50 and S includes all projects with revenue less than 50. When I use the DAX formula:

 

ProjectCategory =

 

VAR Revenue = SELECTDATAVALUE( XXX [YYY])

 

RETURN

SWITCH (TRUE(),

Revenue >= 50, "C",

Revenue <= 50, "S")

 

only projects belonging to category S are represented in the diagram and projects belonging to category C are not included. Does anyone have an idea how I can fix this?

 

Thank you very much and have a nice evening! 🙂

IMG_1078.jpg

3 ACCEPTED SOLUTIONS
Jihwan_Kim
Super User
Super User

Hi,

If you are creating a calculated column (not measure) in the table, please try the below to create a new column.

 

ProjectCategory =
VAR Revenue = XXX[YYY]
RETURN
    SWITCH ( TRUE (), Revenue >= 50, "C", Revenue <= 50, "S" )

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

View solution in original post

@Anonymous 

Thank you for the clarification. Unfortunately it doesn't work like this. You need to create a calculated column as suggested by @Jihwan_Kim and then use it to slice you visual. Then you can create a measure such as COUNTROWS ( TableName ) or just drag the Project column in the Values of the visual ans summarize it by count or distinctcount as needed. 

View solution in original post

Anonymous
Not applicable

Hi @Anonymous ,

 

Please try below steps:

1.Add a new column to table

Project Catagory =
SWITCH (
    TRUE,
    'Table'[Planned Revenue] <= 50, "S",
    'Table'[Planned Revenue] > 50, "C"
)

vbinbinyumsft_0-1658371420976.png

 

2.Visualize the data with pie chart

vbinbinyumsft_1-1658371447395.png

 


Best regards,
Community Support Team_ Binbin Yu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

11 REPLIES 11
Anonymous
Not applicable

Hey @Jihwan_Kim@tamerj1 and @Anonymous it works! Thank you very much guys! 😄

Anonymous
Not applicable

Hi @Anonymous ,

 

Please try below steps:

1.Add a new column to table

Project Catagory =
SWITCH (
    TRUE,
    'Table'[Planned Revenue] <= 50, "S",
    'Table'[Planned Revenue] > 50, "C"
)

vbinbinyumsft_0-1658371420976.png

 

2.Visualize the data with pie chart

vbinbinyumsft_1-1658371447395.png

 


Best regards,
Community Support Team_ Binbin Yu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

Hi @Jihwan_Kim  and @tamerj1, thank you very much guys for your help. I created a new similar Project without important Data and made some Screenshots to show you 🙂

Screenshot 2022-07-18 222726.png

Screenshot 2022-07-18 222701.png

Screenshot 2022-07-18 222629.png

@Anonymous 

Thank you for the clarification. Unfortunately it doesn't work like this. You need to create a calculated column as suggested by @Jihwan_Kim and then use it to slice you visual. Then you can create a measure such as COUNTROWS ( TableName ) or just drag the Project column in the Values of the visual ans summarize it by count or distinctcount as needed. 

Anonymous
Not applicable

Dear @tamerj1, I created a calculated column as you and @Jihwan_Kim suggested but it still doesnt work. As you can see in every row of this created column is S, even when projects x, c and df > then 50 and belong to C. Do you have any Idea why? 

Screenshot 2022-07-19 111311.png

Hi @Anonymous 
Delete SELECTEDVALUE. Just use Table[Column] directly

tamerj1
Super User
Super User

Hi @Anonymous 

double check the data type. The column XXX [YYY] should be of type integer or decimal. 

Jihwan_Kim
Super User
Super User

Hi,

If you are creating a calculated column (not measure) in the table, please try the below to create a new column.

 

ProjectCategory =
VAR Revenue = XXX[YYY]
RETURN
    SWITCH ( TRUE (), Revenue >= 50, "C", Revenue <= 50, "S" )

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.
Anonymous
Not applicable

Hey 🙂 thank you very much for your suggestion! But it still doesn't works 😞

Hi,

Please share your pbix file's link here, and then I can try to look into it to come up with a more accurate solution for your data model.

Thanks.


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.
Anonymous
Not applicable

Thank you very much! But I'm not allowed to share the link because of the confidential data... 😞

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.