cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Federaske
Frequent Visitor

Self referencing calculated column (referencing previous row) - Power M help

Good evening,

 

hope you guys can help me! I inherited an old heavy-hard coded file with various cell references and formulas I am now trying to automate.

I need one last step with my PQ query, I need to add a calculated column that is referencing to the previous row of itself to complete a calculation. @ImkeF, I am mentioning you since I have seen a post which you already solved with a very similar issue (https://community.powerbi.com/t5/Desktop/Calculated-column-with-previous-row-referencing-same-calcul...)

Here below an example of what I need to calculate --> AVAILABLE is the calculated column I need (see on the right the calculation)

 

PRODUCT IDON-ORDERON-HANDAVAILABLE 

ABC

31500469(ONHAND[i] - ONORDER[i])
ABC29500440(AVAILABLE[i-1] - ONORDER[i])
ABC4500436(AVAILABLE[i-1] - ONORDER[i])
DEF26780751(ONHAND[i] - ONORDER[i])
DEF25780726(AVAILABLE[i-1] - ONORDER[i])
DEF89780637(AVAILABLE[i-1] - ONORDER[i])
DEF168780469(AVAILABLE[i-1] - ONORDER[i])
GHI56-36-92(ONHAND[i] - ONORDER[i])
GHI56-36-148(AVAILABLE[i-1] - ONORDER[i])
LMN348220-128.....
LMN26220-154.....
LMN125220-279.....

 

Thank you already for the help.

 

Federico

1 ACCEPTED SOLUTION
V-lianl-msft
Community Support
Community Support

Hi @Federaske ,

 

Please add an index column in the query editor, and then use DAX to create the following new column:

Column = 
var on_order= CALCULATE(SUM('Table'[ON-ORDER]),FILTER(ALLEXCEPT('Table','Table'[PRODUCT ID]),EARLIER('Table'[Index])>='Table'[Index]))
return 'Table'[ON-HAND]-on_order

Vlianlmsft_0-1624244249508.png

 

 

Best Regards,
Liang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
V-lianl-msft
Community Support
Community Support

Hi @Federaske ,

 

Please add an index column in the query editor, and then use DAX to create the following new column:

Column = 
var on_order= CALCULATE(SUM('Table'[ON-ORDER]),FILTER(ALLEXCEPT('Table','Table'[PRODUCT ID]),EARLIER('Table'[Index])>='Table'[Index]))
return 'Table'[ON-HAND]-on_order

Vlianlmsft_0-1624244249508.png

 

 

Best Regards,
Liang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Hi Liang,

thank you very much! Works perfectly.

Thanks again,

Bye,

 

Federico

lbendlin
Super User III
Super User III

You must have an index column somewhere. Please include it in your sample data.

Helpful resources

Announcements
MBAS on Demand

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

July 2021 Update 768x460.png

Check it out!

Click here to read more about the July 2021 Updates

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

Urdu Hindi D365 Bootcamp 768x460.png

Urdu Hindi D365 Bootcamp

Dont miss our very own April Dunnam’s The Developer Guide to the Galaxy! Find out what the Power Platform has to offer for the traditional developer.

Top Solution Authors
Top Kudoed Authors