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
Anonymous
Not applicable

Find value of Previous Row in same column

Hi,

 

For a calculation I need to get value of the previous Row of the same column in PowerBI.
In excel it's pretty simple, the formula goes like this

  • C2 = C1 + (C1 * B2)
  • or Current 'Investment Return' = Previous 'Incestment Return' + (Previous 'Incestment Return' * Current 'Rate')

 

DateRateInvestment Return
  100.00
1/1/202010%110.00
1/2/202020%132.00
1/3/2020-20%105.60
1/4/202025%132.00
1/5/2020-5%125.40
1/6/2020-3%121.64
1/7/20201%122.85
1/8/202025%153.57
1/9/2020-10%138.21
1/10/202020%165.85

 

What I have found is DAX does not allow self-refrencing; is there any way I can get this formula to work.

1 ACCEPTED SOLUTION
camargos88
Community Champion
Community Champion

Hi @Anonymous ,

 

First, create an index column like:

Index = RANKX('Table', 'Table'[Date],,ASC)

 

And this measure:

_InvestimentReturn = EXP(CALCULATE(SUMX('Table', LN(IF('Table'[Index] = 1, 100 * 'Table'[Rate] + 100, 1 + 'Table'[Rate]))), FILTER(ALL('Table'[Date]), [Date] <= MAX([Date]))))
 
Capture.PNG


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!



View solution in original post

4 REPLIES 4
camargos88
Community Champion
Community Champion

Hi @Anonymous ,

 

First, create an index column like:

Index = RANKX('Table', 'Table'[Date],,ASC)

 

And this measure:

_InvestimentReturn = EXP(CALCULATE(SUMX('Table', LN(IF('Table'[Index] = 1, 100 * 'Table'[Rate] + 100, 1 + 'Table'[Rate]))), FILTER(ALL('Table'[Date]), [Date] <= MAX([Date]))))
 
Capture.PNG


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!



amitchandak
Super User
Super User

@Anonymous , You can last day and this day using a date table like this

Last Day Non Continous = CALCULATE(sum('order'[Qty]),filter(all('Date'),'Date'[Date] =MAXX(FILTER(all('Date'),'Date'[Date]<max('Date'[Date])),Table['Date'])))
Day behind Sales = CALCULATE(SUM(Sales[Sales Amount]),dateadd('Date'[Date],-1,Day))

or
This Day = CALCULATE(sum('order'[Qty]), FILTER(ALL('Date'),'Date'[Date]=max('Date'[Date])))
Last Day = CALCULATE(sum('order'[Qty]), FILTER(ALL('Date'),'Date'[Date]=max('Date'[Date])-1))

diff % = divide([This Day]-[Last Day],[Last Day])

 

To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :
https://radacad.com/creating-calendar-table-in-power-bi-using-dax-functions
https://www.archerpoint.com/blog/Posts/creating-date-table-power-bi
https://www.sqlbi.com/articles/creating-a-simple-date-table-in-dax/

See if my webinar on Time Intelligence can help: https://community.powerbi.com/t5/Webinars-and-Video-Gallery/PowerBI-Time-Intelligence-Calendar-WTD-YTD-LYTD-Week-Over-Week/m-p/1051626#M184


Appreciate your Kudos.

Anonymous
Not applicable

@amitchandak , the solution as suggested is doing Sum on an existing Order[Qty] column; while in my case I need the Sum from previous row. Let me explain with an Excel example

 

image.png

 

 

Excel Formula: C2 + (C2 * B3)

The catch is its doing a Running Total, but it needs previous row sum to multiply. 

Anonymous
Not applicable

Note that i have already tried, PreviousDay, Earlier, Rankx etc... they all can get teh previous row, but other column. What I am looking is the same column. I wpuld prefer a DAX over M-Query, but if you have any solution using either, do let me know.

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.

Top Solution Authors