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
Anonymous
Not applicable

Getting value from Hierarchical slicer

Hi All,

Need your help.

I am using a hierarchical filter which is using three fields for hierarchy.

Country 

     State

        City

 

Can we have all the levels from the hierarchy in the Legend area for a Line graph

For example, if country is selected then legend should be selected country, all states from selected country , all cities from selected state. As shown below, in the Hierarchical slicer we have selections USA --> Alabama --> Huntsville three lines in the Line graph to represent selected country, state and city

legend.png

 

 

 

Please let me know how can we acheive this.

 

Thanks

14 REPLIES 14
Anonymous
Not applicable

@Anonymous 

 

I don't think there is a native method implemented in Power BI, however, I feel like this can be achieved in a very very indirect way.

 

Let's say the origin data is something like this

Country       State              City            Value      Year

USAAlabamaHuntsville202019
USANorth CarolinaRaleigh302019
USAAlabamaBessemer152019
USAAlabamaHuntsville52018
USANorth CarolinaRaleigh152018
USAAlabamaBessemer102018

 

From there we create another table that serves as the legend of the visual

 

 

_Legends = UNION(
                SUMMARIZE(Origin,Origin[Country],"Type","Country"),
                SUMMARIZE(Origin,Origin[State],"Type","State"),
                SUMMARIZE(Origin,Origin[City],"Type","City")
            )

 

 

 

we end up with this

USACountry
AlabamaState
North CarolinaState
HuntsvilleCity
RaleighCity
BessemerCity

 

Now let's define a measure that reflects the value corresponding to each level in the dimension table

 

 

Measure = VAR
             _area = FIRSTNONBLANK(_Legends[Country],[Country])
          VAR 
            _legend = FIRSTNONBLANK(_Legends[Type],[Type])
        RETURN
                SWITCH(_legend,
                    "Country",CALCULATE(SUM(Origin[Value]),FILTER(Origin,Origin[Country]= _area)),
                    "State",CALCULATE(SUM(Origin[Value]),FILTER(Origin,Origin[State]=_area)),
                    "City",CALCULATE(SUM(Origin[Value]),FILTER(Origin,Origin[City] = _area)),
                BLANK())

 

 

 

With that being said, attributes which are not included in the filtered table would return blank in the measure defined above (and are by default not visible to the end-user)

 

When a country is selected ...

when a country is selectedwhen a country is selected

 

When a state is selected ...

when state is selectedwhen state is selected

Anonymous
Not applicable

Hi @Anonymous ,

 

Thanks for looking into it.  I am able to get all the levels in the hierarchy in the "legends", as shown in your solution. 

But i have noticed, we dont see the independant values for each level. For example, If we select Country = USA and State= Alabama, then we should see measure value = 75 for USA and 35 for Alabama (as expected solution). But we see measure value = 35 for USA, because once we select the state = Alabama, it filters out all the results for Country, USA

Please advise if there is any solution for this.

 

Many thanks.

 

 

Capture1.PNGCapture2.png

Anonymous
Not applicable

Hi @Anonymous ,

 

Thanks for your reply.

I have followed all the steps that you mentioned. After that i get a blank graph.

May i please request you to share the .pbix file.

 

Thanks.

Anonymous
Not applicable

Hi @Anonymous ,

 

I wasn't able to figure out a way to upload documents to this forum, so please try the link below to see if you could access the sample via google drive

https://drive.google.com/file/d/1vUyWfRGJL0C19jGIGM3-kUkn-IXGFzax/view 

Anonymous
Not applicable

Hi @Anonymous 

Thanks for your reply.

I tried the link, it gives me following error.

Capture1.PNG

Anonymous
Not applicable

I tried using another account to access the file and saw a similar error page for preview (not sure if it is a network error or something) - however, I was able to download the file on clicking the "download" button

Anonymous
Not applicable

Hi @Anonymous 

 

My Legend table look like below. May be Blank graph is due to blank values in Country column. Any idea?

 

Capture3.PNG

Hi @Anonymous ,

Do you mind uploading your PBIX file?

If you can, please upload your PBIX file.

Best Regards,
Lionel chen

Anonymous
Not applicable

Thanks @Anonymous .

 

I am able to download this file. I have followed the same steps but still get the "blank" graph, not sure why 😞

Do you have any idea?

Thanks again.

v-lionel-msft
Community Support
Community Support

Hi @Anonymous ,

I tried to help you to realize your idea, but result is not satisfactory.

a5.png

Maybe you can submit your ideas to Power BI Ideas 

Best regards,
Lionel Chen

 

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

Anonymous
Not applicable

Thanks @v-lionel-msft 

it seems, this is not possible in Power BI. I will post this idea.

 

Thanks

Hi @Anonymous ,

I found a Hierarchical slicer in MarketPlace, maybe it can help you:

g8.PNGg7.PNG

 

Best regards,
Lionel Chen

 

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

Anonymous
Not applicable

Thanks @v-lionel-msft for your reply.

I am already using the Hierarchical slicer, imported from market place. there are three columns used for the slicer, thus creates a hierarchy. Issue is, how can we have all the three fields in the Legend.

thanks.

 

Hi @Anonymous ,

Did @Anonymous 's answer solve your problem?

If it is sloved, could you kindly accept it as a solution to close this case?

If not, please let me know.

Best Regards,
Lionel Chen

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.