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

Learn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register now

Reply
PaulGiscard
New Member

Operation using the previous row data

Hi all,

 

Appologies if this has been answered elsewhere but I can't find a solution that works for me in the other posts... 

 

My problem is I need to add data and use result in the next row.

 

Here is what I'm trying to do:

 

Week noOpening BalanceStorageClosing balance
5value coming from a diferent queryopening balance week 5 + pallets in week 5 Storage week 5 - Pallets out week 5 
6Closing balance week 5Opening balance week 6 + pallets in week 6Storage week 6 - Pallets out week 6

 

The data I have is Opening balance for the first row as a manual input converted to a simple query

 

For the pallets in and out I have it coming from another table which looks like the below:

 

Week noPallets inPallets out
5174197
617674

 

There might be a very easy way to this but I can't find the best option

 

 

Thanks,

 

Paul

 

4 REPLIES 4
artemus
Microsoft Employee
Microsoft Employee

I'm not sure why you think it would take 4 times... but I don't see your dataset.

 

Another option is to adjust the week no for closing balance rows to match the other rows, and then do a pivot to get a column for each event type in a week.

Hi Artemus, I must not understand properly your steps then...

 

Here is the data I'm working with:

A query with my week numbers 

A query which has my total pallets in and total pallets out for the different weeks of my data set (some weeks might be 0 and therefore don't show up in that table)

A query which is drilled down to return the opening balance for the first week.

 

If Week number is n, n+1, etc... I need to create the following table:

Where Opening balance week n is OPWn, Storage is SWn, Closing balance is CBWn

Pallets in week n is PIWn, Pallets out Week n is POWn

Opening balance for the first week is x (manual input)

 

Week numberOpening balanceStorageClosing balance
nxSWn= x + PIWnCBWn = SWn - POWn
n+1OPWn+1 = CBWnSWn+1 = OPWn+1 +PIWn+1CBWn+1 = SWn+1 - POWn+1
n+2OPWn+2 = CBWn+1SWn+2 = OPWn+2 +PIWn+2CBWn+2 = SWn+2 - POWn+2

 

I hope that makes more sense and sorry if the solution is the same, I just can't work out what your instructions mean for my data...

artemus
Microsoft Employee
Microsoft Employee

  1. Create a new query that is a copy of your current one.
  2. Keep only rows that refer to the closing balance.
  3. In your main table remove all closing balance rows.
  4. Subtract 1 from the Week no column.
  5. Merge your closing balance table with your main table using the Week no column.

Thansk for the quick response artemus.

 

I had thought of that, but would that mean that I have to do it 4 times? I might take another look in the morning after a while away from the screen 🙂 

Helpful resources

Announcements
Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.