cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
MrMP
Helper I
Helper I

Result of measure in previous row

Hi,

 

I have table structure like this:

IdentifierRow IndexQuantity (Measure)Price (Measure)Previous Price
ABC12350100190<blank>
ABC12355120202190
ABC12385140196202
ABC12311280210196
ABC12352595204210

Is it possible to get Previus Price as a new measure from the measure? Note that every row has index so basicaly just finding the Price for the previous Row Index where Identifier is the same. I just couldnt make it work in vars.

 

Thank you!

1 ACCEPTED SOLUTION
Jihwan_Kim
Community Champion
Community Champion

I quite do not understand what you want.

I assume you want to change your sample like the below to consider various types of identifiers.

Please check the below picture.

 

Picture2.png

 

Previous Price =
VAR currentrowindex =
MAX ( 'Table'[Row Index] )
VAR currentidentifier =
MAX ( 'Table'[Identifier] )
VAR previousrowindex =
CALCULATE (
MAX ( 'Table'[Row Index] ),
FILTER (
ALL ( 'Table' ),
'Table'[Row Index] < currentrowindex
&& 'Table'[Identifier] = currentidentifier
)
)
RETURN
CALCULATE (
[Price total],
'Table'[Row Index] = previousrowindex
&& 'Table'[Identifier] = currentidentifier
)
 
 

Hi, My name is Jihwan Kim.


If this post helps, then please consider accept it as the solution to help other members find it faster, and give a big thumbs up.


Linkedin: linkedin.com/in/jihwankim1975/

Twitter: twitter.com/Jihwan_JHKIM


If this post helps, then please consider accept it as the solution to help other members find it faster, and give a big thumbs up.


Best regards, JiHwan Kim


Linkedin: https://www.linkedin.com/in/jihwankim1975/

Twitter: https://twitter.com/Jihwan_JHKIM

View solution in original post

6 REPLIES 6
Jihwan_Kim
Community Champion
Community Champion

Hi, @MrMP 

Please try the below.

 

Picture1.png

 

Previous Price =
VAR currentrowindex =
MAX ( 'Table'[Row Index] )
VAR previousrowindex =
CALCULATE (
MAX ( 'Table'[Row Index] ),
FILTER ( ALL ( 'Table' ), 'Table'[Row Index] < currentrowindex )
)
RETURN
CALCULATE ( [Price total], 'Table'[Row Index] = previousrowindex )

 

 

 

 

Hi, My name is Jihwan Kim.

 

If this post helps, then please consider accept it as the solution to help other members find it faster, and give a big thumbs up.

 

Linkedin: linkedin.com/in/jihwankim1975/

Twitter: twitter.com/Jihwan_JHKIM


If this post helps, then please consider accept it as the solution to help other members find it faster, and give a big thumbs up.


Best regards, JiHwan Kim


Linkedin: https://www.linkedin.com/in/jihwankim1975/

Twitter: https://twitter.com/Jihwan_JHKIM

Hi,

 

previusrowindex also has to be constrained to identifier. how to add that?

Jihwan_Kim
Community Champion
Community Champion

Hi, @MrMP 

Thank you for your feedback, and sorry that I quite do not understand your question.

I assume you want to see the previous index number in a table as well.

 

Previous row index =
VAR currentrowindex =
MAX ( 'Table'[Row Index] )
VAR previousrowindex =
CALCULATE (
MAX ( 'Table'[Row Index] ),
FILTER ( ALL ( 'Table' ), 'Table'[Row Index] < currentrowindex )
)
RETURN
 previousrowindex

 

 

Hi, My name is Jihwan Kim.

 

If this post helps, then please consider accept it as the solution to help other members find it faster, and give a big thumbs up.

 

Linkedin: linkedin.com/in/jihwankim1975/

Twitter: twitter.com/Jihwan_JHKIM


If this post helps, then please consider accept it as the solution to help other members find it faster, and give a big thumbs up.


Best regards, JiHwan Kim


Linkedin: https://www.linkedin.com/in/jihwankim1975/

Twitter: https://twitter.com/Jihwan_JHKIM

For Previusrowindex I have to add also filter for Identifier since there are many identifiers in the table.

Jihwan_Kim
Community Champion
Community Champion

I quite do not understand what you want.

I assume you want to change your sample like the below to consider various types of identifiers.

Please check the below picture.

 

Picture2.png

 

Previous Price =
VAR currentrowindex =
MAX ( 'Table'[Row Index] )
VAR currentidentifier =
MAX ( 'Table'[Identifier] )
VAR previousrowindex =
CALCULATE (
MAX ( 'Table'[Row Index] ),
FILTER (
ALL ( 'Table' ),
'Table'[Row Index] < currentrowindex
&& 'Table'[Identifier] = currentidentifier
)
)
RETURN
CALCULATE (
[Price total],
'Table'[Row Index] = previousrowindex
&& 'Table'[Identifier] = currentidentifier
)
 
 

Hi, My name is Jihwan Kim.


If this post helps, then please consider accept it as the solution to help other members find it faster, and give a big thumbs up.


Linkedin: linkedin.com/in/jihwankim1975/

Twitter: twitter.com/Jihwan_JHKIM


If this post helps, then please consider accept it as the solution to help other members find it faster, and give a big thumbs up.


Best regards, JiHwan Kim


Linkedin: https://www.linkedin.com/in/jihwankim1975/

Twitter: https://twitter.com/Jihwan_JHKIM

View solution in original post

sayaliredij
Solution Supplier
Solution Supplier

Hi,

 

You can try the following measures 

 

Previous =
VAR currentindex =
MAX ( 'Table'[Row Index] )
VAR Result =
CALCULATE (
[Price Measure],
'Table'[Row Index] < currentindex
)
RETURN
Result

 

Regards,

Sayali

 

If this post helps, then please consider Accept it as the solution to help others find it more quickly

Helpful resources

Announcements
PBI User Groups

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Get Ready for Power BI Dev Camp

Power BI Dev Camp - June 24th

Mark your calendars and join us for our next Power BI Dev Camp!

Top Solution Authors
Top Kudoed Authors