cancel
Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

Reply
jiangxm80
Regular 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
ryan_mayu
Super User
Super User

@jiangxm80 

you can try to create an index column in PQ

1.PNG

then create a column

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

2.PNG





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

Proud to be a Super User!




View solution in original post

Jihwan_Kim
Super User
Super User

Hi, 

I assume the order is by column 2.

Please check the below picture and the attached pbix file.

 

Jihwan_Kim_0-1668065748372.png

 

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.


Go to My LinkedIn Page


View solution in original post

3 REPLIES 3
Jihwan_Kim
Super User
Super User

Hi, 

I assume the order is by column 2.

Please check the below picture and the attached pbix file.

 

Jihwan_Kim_0-1668065748372.png

 

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.


Go to My LinkedIn Page


resolved, perfect!

ryan_mayu
Super User
Super User

@jiangxm80 

you can try to create an index column in PQ

1.PNG

then create a column

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

2.PNG





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

Proud to be a Super User!




Helpful resources

Announcements
PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

Check out the November 2023 Power BI update to learn about new features.

Community News

Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors