Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago
Solved

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: ...
  • v-yueyunzh-msft's avatar
    3 years ago

    Hi , Anonymous 

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

    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