Power Query Formula

Bonstan

New Member
Joined
Jul 15, 2021
Messages
7
Office Version
  1. 365
Platform
  1. Windows
Can somebody kindly help me with the following problem in the Excel table below? I am a new Power Query user and am trying to combine the rows in Column B for each transaction into a single cell by creating a Custom Column. What formula should I use? i.e.


Table as is

A​
B​
C​
D​
E​
1DateCommentDebitCreditBalance
218/11/2019Cheque 001
150.89​
139.24DR
3REF ZAF-003
4INSTRUCTION 007150.8911.65
629/11/2019Cheque 002
414.93​
209.9​
12GO DIRECT DEBIT
36.45​
173.45​
13TRANSFER REF



Table as I would like it to be

A​
B​
C​
D​
E​
1DateCommentDebitCreditBalance
218/11/2019Cheque 001
150.89​
139.24DR
58/11/2019REF ZAF-003 INSTRUCTION 007150.8911.65
629/11/2019Cheque 002
414.93​
209.9​
1229/11/2019GO DIRECT DEBIT TRANSFER REF
36.45​
173.45​
13

I would appreciate some advice on this. Thank you.
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Welcome!

How do you (or I) know which comment is supposed to go to which transaction (i.e. what is the criteria)? Is there some sort of ID column you can use, or are you looking at whichever row has a date? Based on the table, I initially do not see any kind of repeating pattern that could be used to figure this out.
 
Upvote 0
Welcome!

How do you (or I) know which comment is supposed to go to which transaction (i.e. what is the criteria)? Is there some sort of ID column you can use, or are you looking at whichever row has a date? Based on the table, I initially do not see any kind of repeating pattern that could be used to figure this out.

Thank you for the quick reply and I am sorry if I was not clear enough.

I am looking at whichever row in Column E (Balance)has data in it. Can I explain my problem by referring to the cells in the table below. Row 2 in this table is as I want it to remain because this row has the Date, Comment, Debit or Credit and Balance data all filled up.


A​
B​
C​
D​
E​
1DateCommentDebitCreditBalance
218/11/2019Cheque 001
150.89​
139.24DR
3REF ZAF-003
4INSTRUCTION 007150.8911.65


Regarding Rows 3 and 4, Row 3 has no data in Column E. Therefore the Comments “REF ZAF-003” and “INSTRUCTION 007 “ in Rows 3 and 4 of Column B respectively have to be joined in Row 4, ) because Row 4 has data in the Column E, like thus:

418/11/2019REF ZAF-003 INSTRUCTION 007150.8911.65


The Date should be copied from the closest Date on top of that row. Incidentally, the date in Cell A5 in my original second table should be 18/11/2019 and not 8/11/2019 (my apologies, my mistake).

All data in cells in Column B that have no corresponding data in the same row in Column E should be joined and form part of the next row in Column E with data in it.

In other words, any row in Column E (Balance) that has data in it has to have the data in Column B of that same row populated with data added from the rows above it which have no data in Column E.

If you need any further clarification, please let me know and thank you again for your patience and advice.
 
Upvote 0
Sorry for the long response but I've been busy at work recently. If you are still looking for a solution I should have some time later this week to help out more.
 
Upvote 0
Thankyou for your interest. I am still looking for a solution and would very much appreciate your help. If you need any information please let me know. I look forward to your advice.
 
Upvote 0
Sorry for the long response but I've been busy at work recently. If you are still looking for a solution I should have some time later this week to help out more.
Dear severynm,
Did you find some time to look into my problem?
Thanks
Bonstan
 
Upvote 0
I assume the rules of how to combine rows are still not clear. E7 needs to combine with E6, so why not E3 combine with E2?

1627291888013.png
 
Upvote 0
I assume the rules of how to combine rows are still not clear. E7 needs to combine with E6, so why not E3 combine with E2?

View attachment 43515
B7 has to combine with B6 and B4 has to combine with B3. The rows that have dates on them do not need to be combined. I am not sure whether I am making myself clear. Thanks.
 
Upvote 0
B7 has to combine with B6 and B4 has to combine with B3. The rows that have dates on them do not need to be combined. I am not sure whether I am making myself clear. Thanks.
Each group has 3 rows?
 
Upvote 0
For your reference:

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    res = Table.Combine(Table.Group(Source,"Date",{"n",each let a=Table.Skip(_) in Table.FillDown(Table.FromRecords({_{0},Table.SelectRows(a,(x)=>x[Balance]<>null){0}&[Comment=Text.Combine(_[Comment]," ")]}),{"Date"})},0,(x,y)=>Byte.From(y<>null))[n])
in
    res

1627308023355.png
 
Upvote 0

Forum statistics

Threads
1,223,703
Messages
6,173,977
Members
452,540
Latest member
haasro02

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top