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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
BIFarkas
New Member

DAX Create a measure which referencing to the previously calculated value of itself (previous period

Hi Experts!

 

I would like to create a measure in PowerPivot which referencing the preciously calculated value of itself in the previous iteration.

 

For example: *[Planned Backlog] n = [Planned OIT] period n + (Planned Backlog period n-1 - Planned Revenue period n-1)

 

So technically it is not referencing to itself but to the previous calculated member along the period dimension.

 

It is very easy in excel by referencing a previously calculated cell however in a calculated measure it is tricky. I attached the picture to illustrate how I would do it in excel

PlanningIssue.PNG

 

I want to do this with measure because I want to calculate this dinamically in all the aggregation level. Do you have an idea how can I achieve this? Thanks in advance

4 REPLIES 4

Presumably you can get the individual row measures to work.  The principle is actually quite simple. You need to be able to relatively reference each row, then filter the data to access the previous row. E.g., if there is a period ID integer, you can access that i reger for the current row with MAX().  Therefore the previous row is MAX()-1. Just use a FILTER inside a CALCULATE to access the previous row. 



* Matt is an 8 times Microsoft MVP (Power BI) and author of the Power BI Book Supercharge Power BI.

Hi Matt!

 

Thanks for your suggestion and sorry for not coming back earlier. 

 

Maybe I don't understand your suggestion well but I have a feeling that with your solution I would be able to relatively reference to the previous row from the table context but not the previously calculated value of the same measure. I think for that I would need some kind of recursion. 

 

I also posted the question to StackOverflow and Tom Martens gave me a hint of Using table-iterators to calculate a future value . He also linked a great article about the issue, but unfortunatelly for my problem I didn't managed to apply yet. 

 

I am still working on solving it so should you manage to simulate it in a workbook I would appreciate that. 

 

Have a nice day,

Tom

 

 

@BIFarkas,

 

In Power BI data mode, you cannot refer to previous row directly because there is no row order in your data mode. If you want to get previous row, you need to have index column, and then get the previous row value by using LOOKUPVALUE function.

Column = LOOKUPVALUE(Table2[Value],Table2[Index],Table2[Index]-1)
Capture.PNG

 

Regards,

Charlie Liao

How can you use the beginning balance to trigger a transaction? For example, if beginning balance exceeds $x then $y transaction feeds new $z ending balance. I am trying to create conditional transfers or fees as well as calaculate compounding interest. This can be done in excel with relative ranges but seems DAX prevents since it refers to entire table. 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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