Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
rs1249
Helper I
Helper I

How to reference previous row in the same column

Hi Guys, I had looked at other forum on how to reference previous rows, nothing appears can solve this simple issue I had, well at least it is very simple in excel, but for some reason, in power query, I just can't get it working,

in excel the column formula suppose to work like this below, simple right

rs1249_0-1664839339795.png

But in power query,how do I reference the previous row in the same column?

I got to here but it doesn't work:

= Table.AddColumn(#"Added Index", "Custom", each if [Entry_Type] = "Initial Entry" then [Cust_Ledger_Entry_No] else #"Added Index"[Custom]{[Index]-1})

rs1249_1-1664839808444.png

it gives me the error:

Expression.Error: The column 'Custom' of the table wasn't found.
Details:Custom,

Anyway, here is the table and the end result in excel: the column Cust_Ledger_Entry_No_2 is the calculation column I would like to add

Entry_NoPosting_DateEntry_TypeDocument_TypeDocument_NoCustomer_NoAmountCust_Ledger_Entry_NoCust_Ledger_Entry_No_2
101/10/2017Initial EntryCredit MemoCRD-0000004C0000500-720058025802
201/10/2017ApplicationCredit MemoCRD-0000004C0000500-72001105802
301/10/2017ApplicationCredit MemoCRD-0000004C0000500720058025802
401/10/2017Initial EntryCredit MemoCRD-0000003C0000500-720058055805
501/10/2017ApplicationCredit MemoCRD-0000003C0000500-72001045805
601/10/2017ApplicationCredit MemoCRD-0000003C0000500720058055805
701/10/2017Initial EntryInvoiceINV-0000089C0000500720058245824
824/10/2017Initial EntryInvoiceINV-0000090C0000500288058435843
924/10/2017Initial EntryInvoiceINV-0000091C00005001008058625862
1001/10/2017Initial EntryCredit MemoCRD-0000006C0000490-6000058655865
1101/10/2017ApplicationCredit MemoCRD-0000006C0000490-600001185865
1201/10/2017ApplicationCredit MemoCRD-0000006C00004906000058655865
1301/10/2017Initial EntryInvoiceINV-0000092C000049095999.9658845884
1401/10/2017Initial EntryCredit MemoCRD-0000007C0000420-25259915991
1501/10/2017ApplicationCredit MemoCRD-0000007C0000420-252765991
1601/10/2017ApplicationCredit MemoCRD-0000007C000042025259915991
1701/10/2017Initial EntryCredit MemoCRD-0000008C0000420-35059935993
1801/10/2017ApplicationCredit MemoCRD-0000008C0000420-350785993
1901/10/2017ApplicationCredit MemoCRD-0000008C000042035059935993
2020/11/2017Initial EntryInvoiceINV-0000093C00004201605.660146014
2123/11/2017Initial EntryCredit MemoCRD-0000010C0000560-19260196019
2223/11/2017ApplicationCredit MemoCRD-0000010C0000560-19256686019
2323/11/2017ApplicationCredit MemoCRD-0000010C000056019260196019
2401/10/2017Initial EntryInvoiceINV-0000094C000056019260246024
2501/11/2017Initial EntryInvoiceINV-0000095C000069224.0160276027
2603/10/2017Initial EntryPaymentBANK-0000034C0000430-114.460296029
2703/10/2017ApplicationPaymentBANK-0000034C0000430-114.4846029
2803/10/2017ApplicationPaymentBANK-0000034C0000430114.460296029
2905/10/2017Initial EntryPaymentBANK-0000036C0000610-255.260336033
3005/10/2017ApplicationPaymentBANK-0000036C0000610-255.2746033
3105/10/2017ApplicationPaymentBANK-0000036C0000610255.260336033
3209/10/2017Initial EntryPaymentBANK-0000038C0000630-35.260376037
3311/10/2017Initial EntryPaymentBANK-0000040C0000480-152460416041
3411/10/2017ApplicationPaymentBANK-0000040C0000480-152456996041
3511/10/2017ApplicationPaymentBANK-0000040C0000480152460416041

Thanks very much for the help in advance!!!

1 ACCEPTED SOLUTION
HotChilli
Super User
Super User

The error is thrown because the 'else' clause uses the table as it exists in the previous step, but the column 'custom' doesn't exist at that step.

I think, to keep things simple, if you just use the same code but replace the 'else' part with 'else null', you can add another step afterwards and do a 'Fill Down' that should work.

It will depend on the data being correctly ordered and there being a correct 'Initial Entry' for each 'set' of data

View solution in original post

2 REPLIES 2
HotChilli
Super User
Super User

The error is thrown because the 'else' clause uses the table as it exists in the previous step, but the column 'custom' doesn't exist at that step.

I think, to keep things simple, if you just use the same code but replace the 'else' part with 'else null', you can add another step afterwards and do a 'Fill Down' that should work.

It will depend on the data being correctly ordered and there being a correct 'Initial Entry' for each 'set' of data

Amazing, worked perfactly, thanks very much

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors