Forum Discussion

chrisx's avatar
chrisx
Frequent Visitor
4 years ago
Solved

Cluster Bar Chart and Hierarchy

Hello all,   I have built a clustered bar chart that looks great. The different columns are regions in a data set I am working with. I am having an issue with the slicer I am using.     I ...
  • MFelix's avatar
    MFelix
    4 years ago

    Hi chrisx ,

     

    You need to make a unrelated table and a measure to make this work.

     

    Create the following table:

    Regions =
    UNION (
        ADDCOLUMNS ( DISTINCT ( 'Table'[Region] ), "Category", "Region" ),
        ADDCOLUMNS ( DISTINCT ( 'Table'[SubRegion] ), "Category", "SubRegion" ),
        ADDCOLUMNS ( DISTINCT ( 'Table'[Office] ), "Category", "Office" )
    )

     

     

    Add the following measure to your model:

    Hierarchy Values =
    SWITCH (
        TRUE (),
        HASONEVALUE ( 'Table'[SubRegion] ),
            CALCULATE (
                SUM ( 'Table'[Values] ),
                'Table'[Office] = MAX ( 'Regions'[Region] )
            ),
        HASONEVALUE ( 'Table'[Region] ),
            CALCULATE (
                SUM ( 'Table'[Values] ),
                'Table'[SubRegion] = MAX ( 'Regions'[Region] )
            ),
        CALCULATE (
            SUM ( 'Table'[Values] ),
            'Table'[Region] = MAX ( 'Regions'[Region] )
        )
    )

     

    Now setup your chart in the following way:

    • Axis: Regions[Region]
    • Legend: Table[Cat]
    • Values: [Hierarchy Values]

     

    Check PBIX file attach.