cancel
Showing results for
Did you mean:
Post Prodigy

## Create hierarchy in matrix visual for financial reporting

Hello,

I'm trying to create a hierarchy for a profit and loss statement where accounts have 2 to 9 digits.

For example:

Account nr.    Value

11                      100

111                      20

112                      30

113                      50

So, in Excel I have a column with the account number and 8 other columns to the left with Level2 to Level9 account numbers.

But the problem then is how to create a hierarchy in PBI Desktop that works.

For example, in the table above Level4 is empty, because there are no level 4 accounts. So, creating a hierarchy field and a matrix visual will get me a lot of empty values!

I want to be able to drill down from level 2 to level 9 and always see the correct values.

I've read a lot of stuff in other Posts around the web, including DAX books, etc. But How can I make such a simple visual work?

1 ACCEPTED SOLUTION

Accepted Solutions
Community Support

## Re: Create hierarchy in matrix visual for financial reporting

Hi @webportal,

For you scenario, you can write a recursive calculation to find out the previous parent, then create column parent to store these result.

Sample:

```let
SearchParent=(list as list, item as number)=>
let
temp= if item > 10 then List.Select(list, each _= Int32.From(item/10)) else {item},
result= if List.Count(temp)>0 then List.First(temp) else Search(list, Int32.From(item/10))
in
result
in
SearchParent```

After above steps, you can use these columns to create custom hierarchy.

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin Sheng
If this post helps, please consider Accept it as the solution to help the other members find it more quickly
Learning resources: Power BI
2 REPLIES 2
Community Support

## Re: Create hierarchy in matrix visual for financial reporting

Hi @webportal,

For you scenario, you can write a recursive calculation to find out the previous parent, then create column parent to store these result.

Sample:

```let
SearchParent=(list as list, item as number)=>
let
temp= if item > 10 then List.Select(list, each _= Int32.From(item/10)) else {item},
result= if List.Count(temp)>0 then List.First(temp) else Search(list, Int32.From(item/10))
in
result
in
SearchParent```

After above steps, you can use these columns to create custom hierarchy.

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin Sheng
If this post helps, please consider Accept it as the solution to help the other members find it more quickly
Learning resources: Power BI
Post Prodigy

## Re: Create hierarchy in matrix visual for financial reporting

@v-shex-msft thank you.

Since my knowledge of M is quite limited, I managed to determine the parent in Excel.

Then using PATH and PATHITEM, I've created the hierarchy.

Announcements

#### New Ranks Launched March 24th!

The time has come: We are finally able to share more details on the brand-new ranks coming to the Power BI Community!

#### ‘Better Together’ Contest Finalists Announced!

Congrats to the finalists of our ‘Better Together’-themed T-shirt design contest! Click for the top entries.

#### Arun 'Triple A' Event Video, Q&A, and Slides

Missed the Arun 'Triple A' event or want to revisit it? We've got you covered! Check out the video, Q&A, and slides now.

#### Join THE global Power Platform event series.

Attend for two days of expert-led learning and innovation on topics like AI and Analytics, powered by Dynamic Communities.

#### Community Summit North America

Innovate, Collaborate, Grow. The top training and networking event across the globe for Microsoft Business Applications

Top Solution Authors
Top Kudoed Authors