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
nathanprats
Frequent Visitor

DAX Measure use previous row

Hi all, 

 

I have a DAX measure I'm stuck with for a few days now. 

The idea is to get the "Result" as a DAX measure in PBI. 

Here's the equivalent in Excel : 

  • Result = [@[Previous Result]]*[@Rate]+[@X]

I encouter circular references with PBI, as the Previous Resultreferences the result, and result references the Previous Result.

 

In my screenshot, there are 4 rows, but I could have much more. 

1.png

 

Any idea how to solve this ? 

1 ACCEPTED SOLUTION

Hi @nathanprats

 

So you wanna calculate the value  of “result” by column “Number ”,”x”  and “Rate”,right?

I have modified the measure,pls see below:

Measure = MAX('Table'[Previous Result])*MAX('Table'[Rate])+MAX('Table'[X])
 

You can also create a calculated column,which is as below:

 

Column = 'Table'[Previous Result]*'Table'[Rate]+'Table'[X]

 

With both ways above,you will finally see as below:

 

111.png

 

For the related .pbix file,pls click here.

 

Hope this would help.

 

Best Regards,

Kelly

 

View solution in original post

4 REPLIES 4
v-kelly-msft
Community Support
Community Support

Hi @nathanprats ,

 

What you need to do is to create 3 calculated columns:

1 An index column using query editor, “add column”->”Index column”->”from 1”,then you will see as below:

121.png122.png

 

2.Create a column which calculates the previous result based on the value of “Result”:

Select “calculated column”:

 

 

dax PreviousResult = 
var a ='Table'[Result ]
var b ='Table'[Index]
Return
CALCULATE(SUM('Table'[Result ]),FILTER('Table',[index]=b-1))

 

 

3. Create a column which calculates result based the value of previous result:

 

dax Result = 'Table'[dax PreviousResult]*'Table'[Rate]+'Table'[X]

 

 

Then you will find see as below:

 

123.png

 

For the related .pbix file ,you can turn to URL:https://microsoftapc-my.sharepoint.com/:u:/g/personal/v-kellya_microsoft_com/EUhsDoRxQkREss9Xo4Hawyo...

 

Hope this would help.

 

Best Regards,

Kelly

 

Hi, 

 

This doesn't work, as you're using the result itself in the "dax PreviousResult" column. 

Hi @nathanprats

 

So you wanna calculate the value  of “result” by column “Number ”,”x”  and “Rate”,right?

I have modified the measure,pls see below:

Measure = MAX('Table'[Previous Result])*MAX('Table'[Rate])+MAX('Table'[X])
 

You can also create a calculated column,which is as below:

 

Column = 'Table'[Previous Result]*'Table'[Rate]+'Table'[X]

 

With both ways above,you will finally see as below:

 

111.png

 

For the related .pbix file,pls click here.

 

Hope this would help.

 

Best Regards,

Kelly

 

TomMartens
Super User
Super User

Hey @nathanprats , 

 

I'm wondering if you can adapt this https://www.minceddata.info/2018/02/21/using-table-iterators-to-calculate-a-future-value/ to your needs.

 

Regards,

Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

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.