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
mm808
Regular Visitor

Using SWITCH Function to make a grouped slicer

Hi all,

 

I've been working on making a grouped slicer for a dashboard I'm creating, and I wanted to be able to make groups of countries for the slicer.  I followed the guidance in the below post:

 

https://community.powerbi.com/t5/DAX-Commands-and-Tips/How-to-group-values-in-a-slicer/m-p/2576674#M...

 

I used the following code to try to do this:

 

Group Selection = 
SWITCH (
    TRUE(),
    'Compiled Data'[Country] IN {"USA", "UK", "Germany", "Austria", "Switzerland", "China", "Australia", "Canada"}, "P6",
    'Compiled Data'[Country] IN {"Spain", "Italy", "France", "Taiwan", "Thailand", "Norway", "Denmark", "India", "Sweden"}, "E10",
    'Compiled Data'[Country] IN {"Argentina", "Australia", "Brazil", "Canada", "China", "France", "Germany", "India", "Indonesia", "Italy", "Japan", "Mexico", "South Korea", "Saudi Arabia", "South Africa", "Turkey", "UK", "USA"}, "G20"
)

 

 

However, this returned the below error message:

 

A single value for column 'Country' in table 'Compiled Data' cannot be determined. This can happen when a measure formula refers to a column that contains many values without specifying an aggregation such as min, max, count, or sum to get a single result.

 

 

mm808_0-1669718307786.png

 

I thought it may have been due to the overlapping countries between the final group and the other two, so I tried the same but without the final group and the same error message came up. Any suggestions on how I could fix this?

 

Many thanks!

1 ACCEPTED SOLUTION
v-yueyunzh-msft
Community Support
Community Support

Hi , @mm808 

According to your description, when you use the SWITCH() function, it returns teh error code.

vyueyunzhmsft_0-1669774397260.png

For this , i think you put this code in a measure . Right?

For this code , it should be in the calculated column in your table.Because the 'Compiled Data'[Country] can not be used in the measure. 

In the measure , you need to use the Aggregate functions to get the value, like MAX() , MIN() or SELECTEDVALUE() .

 

You can try to use:

Group Selection = 
SWITCH (
    TRUE(),
    MAX('Compiled Data'[Country]) IN {"USA", "UK", "Germany", "Austria", "Switzerland", "China", "Australia", "Canada"}, "P6",
    MAX('Compiled Data'[Country]) IN {"Spain", "Italy", "France", "Taiwan", "Thailand", "Norway", "Denmark", "India", "Sweden"}, "E10",
    MAX('Compiled Data'[Country]) IN {"Argentina", "Australia", "Brazil", "Canada", "China", "France", "Germany", "India", "Indonesia", "Italy", "Japan", "Mexico", "South Korea", "Saudi Arabia", "South Africa", "Turkey", "UK", "USA"}, "G20"
)

 

If this method does not meet your needs, you can provide us with your special sample data and the desired output sample data in the form of tables, so that we can better help you solve the problem.

Thank you for your time and sharing, and thank you for your support and understanding of PowerBI! 

 

Best Regards,

Aniya Zhang

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

2 REPLIES 2
v-yueyunzh-msft
Community Support
Community Support

Hi , @mm808 

According to your description, when you use the SWITCH() function, it returns teh error code.

vyueyunzhmsft_0-1669774397260.png

For this , i think you put this code in a measure . Right?

For this code , it should be in the calculated column in your table.Because the 'Compiled Data'[Country] can not be used in the measure. 

In the measure , you need to use the Aggregate functions to get the value, like MAX() , MIN() or SELECTEDVALUE() .

 

You can try to use:

Group Selection = 
SWITCH (
    TRUE(),
    MAX('Compiled Data'[Country]) IN {"USA", "UK", "Germany", "Austria", "Switzerland", "China", "Australia", "Canada"}, "P6",
    MAX('Compiled Data'[Country]) IN {"Spain", "Italy", "France", "Taiwan", "Thailand", "Norway", "Denmark", "India", "Sweden"}, "E10",
    MAX('Compiled Data'[Country]) IN {"Argentina", "Australia", "Brazil", "Canada", "China", "France", "Germany", "India", "Indonesia", "Italy", "Japan", "Mexico", "South Korea", "Saudi Arabia", "South Africa", "Turkey", "UK", "USA"}, "G20"
)

 

If this method does not meet your needs, you can provide us with your special sample data and the desired output sample data in the form of tables, so that we can better help you solve the problem.

Thank you for your time and sharing, and thank you for your support and understanding of PowerBI! 

 

Best Regards,

Aniya Zhang

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

Thanks very much, setting it as a table worked far better. However, there are some categories that overlap and the table only sees one of these values. Is there a way to fix this so that I can use this properly in a slicer?

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.