Forum Discussion

Ira_27's avatar
Ira_27
Helper II
1 year ago
Solved

Power Query - Recursive decomposition of rows

Hello Community Members,   I am trying to get some help with a scenario we are dealing with. We have daily holdings data and need a way to drill into the subsequent fund holdings to find % investme...
  • Sahir_Maharaj's avatar
    1 year ago

    Hello Ira_27,

     

    Can you please try this approach:

     

    1. Create a Recursive Table

    DecomposedHoldings = 
    VAR FundHoldings = 
        GENERATE(
            'Holdings',
            FILTER(
                'Holdings',
                'Holdings'[FundID] = EARLIER('Holdings'[AccountID])
            )
        )
    RETURN
        UNION('Holdings', FundHoldings)
    

     

    2. Calculate % Investment

    % Investment = 
    VAR TotalMV =
        CALCULATE(
            SUM('DecomposedHoldings'[MV]),
            ALL('DecomposedHoldings')
        )
    RETURN
        DIVIDE(SUM('DecomposedHoldings'[MV]), TotalMV, 0)
    

     

    3. If the semantic model's size is an issue, filter the data in Power Query:

    FilteredHoldings = Table.SelectRows(
        Source,
        each [HoldingDate] >= Date.AddMonths(DateTime.LocalNow(), -24)
    )
    

     

    Hope this helps!