Forum Discussion
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?
- Anonymous9 years ago
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 SearchParentAfter above steps, you can use these columns to create custom hierarchy.
Regards,
Xiaoxin Sheng
2 Replies
- AnonymousNot applicable
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 SearchParentAfter above steps, you can use these columns to create custom hierarchy.
Regards,
Xiaoxin Sheng
- webportal
Impactful Individual
Anonymous 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.