Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Power-Geek
New Member

How to create hierarchy when Hierarchy levels are read from a database table

Hello, 

I need to read the hierarchy levels from a database table and can be different for different customer. For example

AttributeIdAttributeHierarchyLevelAttribute
31DEPARTMENT
82SUB_DEPARTMENT
23CATEGORY

There is a table that has records for the products and their attributes. As there are three levels of hierarchy, there are three records per product. For example the product 2784580201 is in the Departmen General Merchandise, Sub-department of Novelty Items and Category of Novelty. 

The attributes are read from the database and the hierarchy needs to be created dynamically based on what attributes and levels are retrieved from the database.

 

ProductIdAttributeIdAttributeAttributeValueAttributeHierarchyLevelAttDesc
27845802013DEPARTMENT1301GENERAL MERCHANDISE
27845802018SUB_DEPARTMENT93402NOVELTY ITEMS
27845802012CATEGORY9311943NOVELTY
57511131053DEPARTMENT1001GROCERY
57511131058SUB_DEPARTMENT91352PASTRIES AND CAKES
57511131052CATEGORY9112353PASTRIES
9897708933DEPARTMENT1301GENERAL MERCHANDISE
9897708938SUB_DEPARTMENT93752TOYS KNIVES CARDS
9897708932CATEGORY9313803TOYS
232020273DEPARTMENT1301GENERAL MERCHANDISE
232020278SUB_DEPARTMENT93402NOVELTY ITEMS

 

Then I have a usual sales table for the products. 

How can I create hierarchy based on the hierarchy levels read from the database table? Can someone point me to any documents/solutions?

2 REPLIES 2
v-jingzhang
Community Support
Community Support

Hi @Power-Geek 

 

Is it possible to create a relationship between Hierarchy Level table and Product table on AttributeId or AttributeHierarchyLevel column? Then use RELATED() function to get the value you want from the Hierarchy Level table into the other table.

 

Or since every product has three levels, combine product and level columns to create a unique ID column, for example, 'Table'[ProductId] & "-" & 'Table'[AttributeHierarchyLevel]

 

Best Regards,
Community Support Team _ Jing

Thank you for the reply v-jingzhang

The hierarchy levels are going to be variable ( there could be 3, 4, or 5 levels based on customer) and need to be dealt with dynamically. (And I am brand new to PBi)

 

I created a table like below and the pivoted on the Attribute column.

 

ProductIdAttributeAttDesc
32784580201Column-1GENERAL MERCHANDISE
32784580201Column-2NOVELTY ITEMS
32784580201Column-3NOVELTY
35751113105Column-1GROCERY
35751113105Column-2PASTRIES
35751113105Column-3PASTRIES
3989770893Column-1GENERAL MERCHANDISE
3989770893Column-2TOYS KNIVES CARDS
3989770893Column-3TOYS
4023202027Column-1GENERAL MERCHANDISE
4023202027Column-2NOVELTY ITEMS
4023202027Column-3NOVELTY

 Now my table has columns Product_id, Column-1, column-2 and column-3.

Column-1,column-2 and column-3 represent the hierarchies (Department, Sub-dept, Category). 

 

When creating a hierarchy slicer, I need to pull Column-1, column-2 and column-3 ( to column-n) and Product_id onto the "Field" area for the visual. Is there a way that all the columns in a table be pulled on the "Field" for the slicer visual without knowing the column names??

 

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.