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

Microsoft is giving away 50,000 FREE Microsoft Certification exam vouchers. Get Fabric certified for FREE! Learn more

Reply
Gérale-Récolte
Frequent Visitor

Dataflow : recreating a hierarchy from self referencing table

Hi

 

I'm setting up a new dataviz project for my company and I have a use case that I want to submit to this very active and great community 🙂

 

Context : all our data are stored in a postgre db. I connect to this db and load / transform data through a dataflow. Then my users will create reports based on a dataset that will be refreshed by the dataflow I mentionned above.

 

Problem I face : among the tables in the postgre db we have a table that contains the categories for our product. The table is self referencing with a structure like this :

category_idcategory_namecategory_parent_idcategory_parent_name
C001name001nullnull
C002name002C001name001
C003name003C001name001
C004name004C002name002
............

 

This creates a hierarchy of categories in which we publish our products. The hierarchy can be up to 4 levels. For instance :

Fruits & vegetable > Fruits > Apples > Golden

Fruits & vegetable > Fruits > Mango

 

We need this hierarchy in powerBI in order to group metrics per category (for instance, measuring the sales for one level of the category)

 

My first idea for a solution : 

My first guess is to use the transformation capabilities of dataflows to recreate a table that contains the hierarchy :

Level 1Level 2Level 3Level 4category_id
name001nullnullnullC001
name001name002nullnullC002
name001name003nullnullC003
name001name002name004nullC004
...   

 

 

If I can recreate this table, then I should be able to use it in powerBI reports, shouldn't I ?

 

My questions are the following :

  1. Is this the best solution to achieve what I want ? should this transformation be done in the dataflow or elsewhere in powerBI ?
  2. If the dataflow is the right tool to do it, how can I recreate the table from the self referencing category table ?

 

Thanks for your help !

 

Gérald

1 ACCEPTED SOLUTION

The DAX functions are created specifically for this purpose, for me I would stick with that.

You could replicate this in your dataflow, or even in your warehouse by creating a flattened hierarchy. If your hierarchy will have the same amount of levels it would make sense to do it at warehouse and store as a table for the sake of using in multiple report solutions.

View solution in original post

6 REPLIES 6
ajohnso2
Super User
Super User

Hi, 

Please read through this.

 

https://learn.microsoft.com/en-us/dax/understanding-functions-for-parent-child-hierarchies-in-dax 

 

In addition you may want to take a look at 'Hierarchy Slicer' visual from the market place which offers more features than the standard microsoft visual

Hi @ajohnso2 

 

Thanks for your reply. I read the document you shared with me. I think DAX could be a good solution but I'm wondering if I'd rather do the transformation in the dataflow itself.

 

So i tried the following solution :

  1. In power query M, I created a function that parses the entries in the categories db and get all the ancestors for one category. I don't think there is a function similar to the ones in DAX so I had to create one. It's a recursive function that navigates in the hierarchy and collects all the ancestors of one category
  2. I create as many columns as needed and store the values of ancestors in each column

What do you think of this solution ? Should I keep it or aim for a transformation in the dataset with DAX ?

I find it hard to decide what's the best implementation.

 

BR

 

Gérald

The DAX functions are created specifically for this purpose, for me I would stick with that.

You could replicate this in your dataflow, or even in your warehouse by creating a flattened hierarchy. If your hierarchy will have the same amount of levels it would make sense to do it at warehouse and store as a table for the sake of using in multiple report solutions.

Hi @ajohnso2 

I think that I'd rather put it in the dataflow when transforming data rather than in the dataset or any report with DAX. Indeed, I feel that I should prepare data as early as possible in the data loading process and then make it available to all users with a shared syntax. This would allow us to ensure consistency through all reports.

 

https://www.youtube.com/watch?v=a1PAOeonCcc 

 

This video explains the solution in great detail

Thanks for sharing the link !

Helpful resources

Announcements
PBIApril_Carousel

Power BI Monthly Update - April 2025

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

Notebook Gallery Carousel1

NEW! Community Notebooks Gallery

Explore and share Fabric Notebooks to boost Power BI insights in the new community notebooks gallery.

April2025 Carousel

Fabric Community Update - April 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors