Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

IF-statement to categorize a dimension

I have a dimension (customer) and want to categorize them into group A and group B based on numbers of products they have.

So I want an IF-statement so customers with more than 1000 prodoucts is group A and 0-1000 products is group B.

 

I want to create a custom column so I can have it as a legend in a donut chart.

 

 

I hope someone can help me create the correct DAX.

 

Thanks in advance 🙂

  • Anonymous's avatar
    Anonymous
    4 years ago

    Hi Anonymous 

    _Count is incorrect in goncalogeraldes's code. If you only use count function instead of calcualte and count, you will get the whole count from your Data table. Try code as below. And Klassifikation should be a calculated column instead of a measure. We could only add a column in Legend or Detail in Donut visual.

    Klassifikation = 
    VAR _Count = CALCULATE(COUNT(Data[Products]))
    RETURN
    IF(
    _count >= 1000,
    "A",
    "B")

    Result: 

    Best Regards,
    Rico Zhou

     

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

5 Replies

  • Hello there Anonymous ! 

    Klassifikation =
    var _count = Count(Table[Products])
    
    return
    IF(
    _count >= 1000,
    "A",
    "B")

     

    Hope this answer solves your problem! If you need any additional help please @ me in your reply.
    If my reply provided you with a solution, pleased mark it as a solution ✔️ or give it a kudoe 👍
    Thanks!

    You can also check out my LinkedIn!

    Best regards,
    Gonçalo Geraldes

    • Anonymous's avatar
      Anonymous
      Not applicable

      When I do it like that I can only see it in a table. When I try to make a donut chart it will only let it put it in the "tool-tips" window. Any ways to fix this?

       

      • goncalogeraldes's avatar
        goncalogeraldes
        Icon for Super User rankSuper User

        Hello there Anonymous ! For a donut chart you need numeric value so it has to be like this:

         

        Klassifikation =
        var _count = Count(Table[Products])
        
        return
        IF(
        _count >= 1000,
        1,
        2)

         

        Hope this answer solves your problem! If you need any additional help please @ me in your reply.
        If my reply provided you with a solution, pleased mark it as a solution ✔️ or give it a kudoe 👍
        Thanks!

        You can also check out my LinkedIn!

        Best regards,
        Gonçalo Geraldes