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
PowerBIFin
Helper I
Helper I

New Measure based on the previous "row" value of another measure

 

Index is an actual column and Value is a measure (table below).

 

How can I get the result of the previous row in a new measure?

 

I want to use measure as this "Value' is a result of aggregation through a few visualization filters. 

 

 

Index (Column)Value (Measure)PrevRowValue (Measure - HOW?)
0(146,978,613) 
1(158,041,519)(146,978,613)
2(509,767,635)(474,083,901)
3(1,049,965,114)(976,467,556)
4(2,027,531,439)(1,885,604,238)
5(3,279,221,394)(3,049,675,897)
6(4,336,233,512)(4,032,697,166)
1 ACCEPTED SOLUTION
v-danhe-msft
Employee
Employee

Hi @PowerBIFin,

Could you mean to get the value in previous row? If so, you could refer to below steps:

Sample data:

1.PNG

Create below measure:

Previous row value = var a=CALCULATE(SUM(Table1[Index]))-1
return CALCULATE(MAX('Table1'[Value]),FILTER(ALL('Table1'),'Table1'[Index]=a))

Result:

1.PNG

You could also download the pbix file to have a view.

 

Regards,

Daniel He

 

Community Support Team _ Daniel He
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

6 REPLIES 6
v-danhe-msft
Employee
Employee

Hi @PowerBIFin,

Could you mean to get the value in previous row? If so, you could refer to below steps:

Sample data:

1.PNG

Create below measure:

Previous row value = var a=CALCULATE(SUM(Table1[Index]))-1
return CALCULATE(MAX('Table1'[Value]),FILTER(ALL('Table1'),'Table1'[Index]=a))

Result:

1.PNG

You could also download the pbix file to have a view.

 

Regards,

Daniel He

 

Community Support Team _ Daniel He
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

Hi  @v-danhe-msft !!

 

This is exactly what I am looking for for my model. I need to get the previous value from my index [Trade_day]. But the measure above doesnt work for me. Maybe is because my table has another layer of complexity?

I have an index count for each category [contract_year] I have been trying to figure out this one for days. Any advice is highly appreciated it.

 

For each contract year my index starts at 1 and ends at 250 and resets at 1 again for different value in [Contract Year]. Maybe thats why.

 

This is my dax 

Previous row value = var a=CALCULATE(SUM(Winter_Contracts_Zema[Trade Day])) -1
return CALCULATE([Norm. Price],FILTER(ALL('Winter_Contracts_Zema'),'Winter_Contracts_Zema'[Trade Day]=a))
 
My measure Value is: 
Norm. Price = CALCULATE(SUM(Winter_Contracts_Zema[Price])) + 'Normalized Value'[Normalized Value Value]
 
Normalized Value is a parameter table that adds a number to my price from 1 to 5 depending on selection as shown below
 
CapturePR.PNG

On the left you can see the values Im trying to get and on the right the measure for previous row which seems like is agregating the trade_day data.

 

This is my raw data filtered by index value = 2. so you can see there is a unique 2 for each [Contract Year] 

 

Capturetable.PNG

 

I hope it makes sense, any advice is very much appreciated.

 

 

 

 

Anonymous
Not applicable

I was able to solve this one with the following measure corrections! See below

 

Previous P = VAR AB = MIN(Winter_Contracts_Zema[Trade Day])-1 
RETURN
CALCULATE([Norm. Price Final F],'Winter_Contracts_Zema'[Trade Day]=AB)

Thanks for your help!

 

Your solution gave me an idea what I've been doing wrong and it worked. 🙂

 

Wrong_Measure2 =
VAR A = [_Index]-1 // PREVIOUS ROW INDEX
RETURN
CALCULATE([Measure1],'Tbl LRA Summary'[_Index]=a)
 
Right_Measure2 =
VAR A = MIN([_Index])-1 // PREVIOUS ROW INDEX
RETURN
CALCULATE([Measure1],'Tbl LRA Summary'[_Index]=a)
Anonymous
Not applicable

This is helpful. 

Ashish_Mathur
Super User
Super User

Hi,

 

Share the link from where i can download your PBI file.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

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.