cancel
Showing results for
Did you mean:

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Frequent Visitor

## Calculate the value from previous row

I have a table as the following.

Column1    Column2

A                 1000

B                   800

B                   500

B                   300

I would like to create one more column

Column1    Column2   Column3

A                 1000            200

B                   800            300

B                   500            200

B                   300            300

How could I make that?

Thanks.

2 ACCEPTED SOLUTIONS
Super User

you can try to create an index column in PQ

then create a column

``````Column =
VAR _next=maxx(FILTER('Table','Table'[Index]=EARLIER('Table'[Index])+1),'Table'[Column2])
return 'Table'[Column2]-_next``````

Proud to be a Super User!

Super User

Hi,

I assume the order is by column 2.

Please check the below picture and the attached pbix file.

``````Column3 CC =
VAR _number =
MAXX (
FILTER ( Data, Data[Column2] < EARLIER ( Data[Column2] ) ),
Data[Column2]
)
RETURN
IF ( NOT ISBLANK ( _number ), Data[Column2] - _number, Data[Column2] )
``````

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

3 REPLIES 3
Super User

Hi,

I assume the order is by column 2.

Please check the below picture and the attached pbix file.

``````Column3 CC =
VAR _number =
MAXX (
FILTER ( Data, Data[Column2] < EARLIER ( Data[Column2] ) ),
Data[Column2]
)
RETURN
IF ( NOT ISBLANK ( _number ), Data[Column2] - _number, Data[Column2] )
``````

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

Frequent Visitor

resolved, perfect!

Super User

you can try to create an index column in PQ

then create a column

``````Column =
VAR _next=maxx(FILTER('Table','Table'[Index]=EARLIER('Table'[Index])+1),'Table'[Column2])
return 'Table'[Column2]-_next``````

Proud to be a Super User!

Announcements

#### Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

#### Power BI Monthly Update - June 2024

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

#### Fabric Community Update - June 2024

Get the latest Fabric updates from Build 2024, key Skills Challenge voucher deadlines, top blogs, forum posts, and product ideas.

Top Solution Authors
Top Kudoed Authors