Forum Discussion

thrillhouse's avatar
thrillhouse
Helper I
4 years ago

Using Range Bins as Legend Categories

Hello, I am trying to use ranges that I've created from a nother calculated field.  I am taking a distinct count of certain categories and then I've created a range out of this distinct count:

 

Main Categories Count =
CALCULATE (
DISTINCTCOUNT ( [Category]),
[Category] = "Cat1"
|| [Category] = "Cat2"
|| [Category] = "Cat3"
|| [Category] = "Cat4"
|| [Category] = "Cat5"
)
 
 
Range Bins =
IF (
[Main Categories Count] < 3,
"0-2",
IF (
[Main Categories Count] >2
&& [Main Categories Count] <5,
"2-4",
IF ( [Main Categories Count] > 4, "5+")
)
)
 
I'm unable to make this function properly as a legend.  The only value that displays in the legend is the first bin (0-2).  The field is working properly as I can see the bins displaying properly in a table, however, it just doesn't want to work as a legend.
 
Any help is greatly appreciated!
 
Thanks!

4 Replies

  • TheoC's avatar
    TheoC
    Community Champion

    Hi thrillhouse 

     

    Can you create a calculated column as follows:

     

    Column =

    SWITCH (
         TRUE () ,
              [Main Categories Count] < 3 , "0-2" ,
              [Main Categories Count] < 5 , "2-4" ,
              "5+" )

    Hope this helps.

    Theo

     

  • Thanks, Theo.  I tried this as well, however, this also only display "0-2" as the only values even though that is not the case.  This column doesn't display the correct values when in a table either.  The IF statement I pasted above shows the correct values in a table, but doesn't seem to work as a legend.

    • TheoC's avatar
      TheoC
      Community Champion

      thrillhouse then it's related to the measure that you referenced.  Use the following measure and it will fix the issue:

       

      Measure =

      VAR _1 = COUNTROWS ( 'Table' )
      RETURN
      SWITCH (
           TRUE () ,
                _1 < 3 , "0-2" ,
                _1 < 5 , "2-4" ,
                "5+" )

      Hope this helps.

      Theo

  • Hi, thrillhouse 

     

    Could you please consider sharing more details about it and posting expected result so it is clear on what needs to be implemented?  And It would be great if there is a sample file without any sesentive information here.

     

    It makes it easier to give you a solution.

    1. Sample (dummy dataset) data as text, use the table tool in the editing bar
    2. Expected output from sample data
    3. Explanation in words of how to get from 1. to 2.

     

    Best Regards,
    Community Support Team _ Zeon Zheng

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