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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
SMARTbyte
New Member

Recursive Measure with Parent-Child Relation

I know recursive measures have been discussed a few times in the Forum, but none of the solutions solve this issue:
First of all we are operating in Direct Query Mode:

We have a Ledger Table with Entries like:

AccountValue
11123
11156
11213
55527

 

And we have an Account table like:

AccParent
1 
111
11111
11211
555
55555

 

What I now try to achieve is to summarize the Values on their respective Account Levels.

 

My Idea was to create a Measure in the Account Table like:

Account.Amount = SUM(Ledger.Value)

 

I have this, and it works fine, but what I would now need to cover the higher accounts in the hierarchy is:

Account.Amount = SUM(Ledger.Value) + CALCULATE(SUM(ChildAccount.Amount), ChildAccount.Parent = ThisAccount.Acc)

 

Or in Words: When I am on a Child Record, summarize the Value in the Ledger,

If I am on a parent Record, summarize the Value in the Ledger, and add the (summarized Value) from the Child Accounts.

And I need to be able to do this recursive Measure through 3-9 Account Measure Levels?

 

If DAX would be a programming Language that would not be a problem, but esp. with Direct Queries in Mind, I know it is not that easy.

 

I don't know if that helps, but on option that came to my mind was, to have kind-of a lookup funtion for all Sub-Level Accounts, and then create a generic filter on the Ledger like CALC(SUM(Ledger.Value), Filter(ACC IN ("ListOfAccounts"))
But then I would have to create this Account Filter List recursively, but it would be less stress on the DB.

 

(Both Tables Ledger and Account are highly simplified in my example, they are very wide in real life!)

 

Kind regards,

Jörn. (or Joern for US keyboards!)

1 REPLY 1
lbendlin
Super User
Super User

Make sure the empty parents are truly nulls, not empty strings.  Then use a local data model and try to create a calculated column with a PATH statement.  This may not work as generally calculated columns in a Direct Query scenario are limited to the same row.  Can you add the PATH in your data source?

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

Feb2025 NL Carousel

Fabric Community Update - February 2025

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