transpose data to header based on column and merging for each date

Ali M

Active Member
Joined
Oct 10, 2021
Messages
290
Office Version
  1. 2019
  2. 2013
Platform
  1. Windows
Hi experts
I want transpose data to header based on column B and merge duplicates items for each duplicated date .
so I put the expected result in F:N, but there is problem about items PR_0000,SR_0000 as in columns J,K but in column B will be different numbers and could be difficult to merge the same date with different duplicate but in reality I want merging , for instance date : 13/06/2023 contains PR_000023,PR_000024 so when merge just match partial item PR_0000 to merge and sum =2000+3000=5000 in J2, the same thing about SR_0000 otherwise for the others items will be the same items when sum . as to OPENING item should ignore it I don't need it .
it should merge the amounts for each item whether in DEBIT or CREDIT .
every time I want adding data so automatically will clear data in column F:N and will insert TOTAL row to sum for each header and calculate as I put the formula in column BALANCE .

AL.xlsm
ABCDEFGHIJKLMN
1DATEDESCRIBEDEBITCREDITDATEBANKCASHREC DEBTPR_0000SR_0000PAID PRPAID EXBALANCE
213/06/2023OPENING387,148.00
313/06/2023PR_0000232,000.00
413/06/2023PR_0000243,000.00
513/06/2023CASH10,000.00
613/06/2023PAID PR2,000.002,000.00
713/06/2023PAID PR1,000.00
813/06/2023REC DEBT100,000.00
913/06/2023REC DEBT3,000.00
1013/06/2023CASH2,000.00
1113/06/2023BANK3,000.00
1213/06/2023BANK1,000.00
1314/06/2023PR_0000252,000.00
1414/06/2023SR_000023331,000.00
1514/06/2023SR_000023342,000.00
1614/06/2023PAID EX10,000.00
1714/06/2023PAID EX20,000.00
1814/06/2023PR_0000263,000.00
1914/06/2023PR_0000274,000.00
2015/06/2023CASH1,200.00
2115/06/2023CASH7,000.00
2215/06/2023PR_00002814,060.00
RAB



result
AL.xlsm
ABCDEFGHIJKLMN
1DATEDESCRIBEDEBITCREDITDATEBANKCASHREC DEBTPR_0000SR_0000PAID PRPAID EXBALANCE
213/06/2023OPENING387,148.0013/06/20234,000.0012,000.00103,000.005,000.00-3,000.00-79,000.00
313/06/2023PR_0000232,000.0014/06/2023---90003000-30,000.00-39,000.00
413/06/2023PR_0000243,000.0015/06/2023-8,200.00-14,060.00---22,260.00
513/06/2023CASH10,000.00TOTAL4,000.0020,200.00103,000.0028,060.003,000.003,000.0030,000.0045,800.00
613/06/2023PAID PR2,000.002,000.00
713/06/2023PAID PR1,000.00
813/06/2023REC DEBT100,000.00
913/06/2023REC DEBT3,000.00
1013/06/2023CASH2,000.00
1113/06/2023BANK3,000.00
1213/06/2023BANK1,000.00
1314/06/2023PR_0000252,000.00
1414/06/2023SR_000023331,000.00
1514/06/2023SR_000023342,000.00
1614/06/2023PAID EX10,000.00
1714/06/2023PAID EX20,000.00
1814/06/2023PR_0000263,000.00
1914/06/2023PR_0000274,000.00
2015/06/2023CASH1,200.00
2115/06/2023CASH7,000.00
2215/06/2023PR_00002814,060.00
RAB
Cell Formulas
RangeFormula
N2:N4N2=I2-(G2+H2+J2+L2+M2)
G5:M5G5=SUM(G2:G4)
N5N5=I5-(G5+H5+L5+M5)
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Are you familiar with Power Query?...and would you consider a solution using it? That's what I would recommend for this type of problem.
 
Upvote 0
Are you familiar with Power Query?...and would you consider a solution using it? That's what I would recommend for this type of problem.
first I suspect PQ overcome all of cases !
second in reality most of time I use office version 2013 .
third if you can help by vba or formula will be ok
 
Upvote 0
I believe PQ would handle your problem, but if you are using Excel 2013, you would need to install the free PQ add-in from Microsoft. I noticed that MS is no longer updating the add-in for Excel versions prior to 2016. If you do try PQ, the following M code produces a summary table whose upper corner is F3 (I haven't added a final total row in this example):
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"DATE", type date}, {"DESCRIBE", type text}, {"DEBIT", Int64.Type}, {"CREDIT", Int64.Type}}),
    #"Filtered Rows" = Table.SelectRows(#"Changed Type", each ([DESCRIBE] <> "OPENING")),
    #"Added Conditional Column" = Table.AddColumn(#"Filtered Rows", "DESCRIPTION", each if Text.Contains([DESCRIBE], "PR_0000") then "PR_0000" else if Text.Contains([DESCRIBE], "SR_0000") then "SR_0000" else [DESCRIBE]),
    #"Replaced Value" = Table.ReplaceValue(#"Added Conditional Column",null,0,Replacer.ReplaceValue,{"DEBIT", "CREDIT"}),
    #"Added Custom" = Table.AddColumn(#"Replaced Value", "AMOUNT", each [CREDIT]-[DEBIT]),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"DESCRIBE", "DEBIT", "CREDIT"}),
    #"Pivoted Column" = Table.Pivot(#"Removed Columns", List.Distinct(#"Removed Columns"[DESCRIPTION]), "DESCRIPTION", "AMOUNT", List.Sum),
    #"Replaced Value1" = Table.ReplaceValue(#"Pivoted Column",null,0,Replacer.ReplaceValue,{"PR_0000", "CASH", "PAID PR", "REC DEBT", "BANK", "SR_0000", "PAID EX"}),
    #"Reordered Columns" = Table.ReorderColumns(#"Replaced Value1",{"DATE", "BANK", "CASH", "REC DEBT", "PR_0000", "SR_0000", "PAID PR", "PAID EX"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Reordered Columns",{{"BANK", type number}}),
    #"Added Custom1" = Table.AddColumn(#"Changed Type1", "Balance", each [BANK]+[CASH]+[REC DEBT]+[PR_0000]+[SR_0000]+[PAID PR]+[PAID EX])
in
    #"Added Custom1"
I believe there are some discrepancies due to how credits and debits are handled. In this example, I've simply taken Credits-Debits, essentially treating Debits as negative numbers to be summed with positive Credits. But if you are using accounting principles where some account categories are Debit accounts and others are Credit accounts, debit and credit transactions may be handled in the opposite manner. So this implementation may not be entirely correct. Please have a look and let me know which items in the Describe column treat the values in the Credit column as positive values and which Describe items treat the Debit values as negative values. Another approach that relies on formulas to construct a list of unique dates and then gathers the appropriate terms for the date and column is shown in the table whose upper corner is F9:
MrExcel_20230619.xlsx
ABCDEFGHIJKLMN
1DATEDESCRIBEDEBITCREDITDATEBANKCASHREC DEBTPR_0000SR_0000PAID PRPAID EXBALANCE
26/13/2023OPENING387,148.00
36/13/2023PR_0000232,000.00DATEBANKCASHREC DEBTPR_0000SR_0000PAID PRPAID EXBalance
46/13/2023PR_0000243,000.006/13/2023400012000-10300050000-10000-83000
56/13/2023CASH10,000.006/14/20230009000-300003000036000
66/13/2023PAID PR2,000.002,000.006/15/20230820001406000022260
76/13/2023PAID PR1,000.00
86/13/2023REC DEBT100,000.00
96/13/2023REC DEBT3,000.00DATEBANKCASHREC DEBTPR_0000SR_0000PAID PRPAID EXBALANCE
106/13/2023CASH2,000.006/13/20234,000.0012,000.00(103,000.00)5,000.00-(1,000.00)-(83,000.00)
116/13/2023BANK3,000.006/14/2023---9,000.00(3,000.00)-30,000.0036,000.00
126/13/2023BANK1,000.006/15/2023-8,200.00-14,060.00---22,260.00
136/14/2023PR_0000252,000.00 --------
146/14/2023SR_000023331,000.00TOTAL4,000.0020,200.00(103,000.00)28,060.00(3,000.00)(1,000.00)30,000.00(24,740.00)
156/14/2023SR_000023342,000.00
166/14/2023PAID EX10,000.00
176/14/2023PAID EX20,000.00
186/14/2023PR_0000263,000.00
196/14/2023PR_0000274,000.00
206/15/2023CASH1,200.00
216/15/2023CASH7,000.00
226/15/2023PR_00002814,060.00
RAB_1
Cell Formulas
RangeFormula
G10:M13G10=SUMPRODUCT($D$2:$D$22-$C$2:$C$22,($A$2:$A$22=$F10)*(LEFT($B$2:$B$22,LEN(G$9))=G$9))
N10:N13N10=SUM(G10:M10)
G14:N14G14=SUM(G10:G13)
F10:F13F10=IFERROR(INDEX($A$2:$A$22, MATCH(0,INDEX(COUNTIF($F$9:F9, $A$2:$A$22),0,0),0)),"")
 
Upvote 0
May you check some values errors contains bracket ,please?
 
Upvote 0
I do not understand your latest request. Above I mentioned:
But if you are using accounting principles where some account categories are Debit accounts and others are Credit accounts
...I should have said "where different account types handle debits and credits differently". But now I am not sure this matters. I believe you want to consider each record (row) as a positive value and then account for whether it is to be added or subtracted in the last Balance column. I suspect there is an error in your original table:
MrExcel_20230619.xlsx
ABCD
66/13/2023PAID PR2,000.002,000.00
RAB

Did you intend for 2000 to be shown in both the Debit column and the Credit column? Your expected results do not appear to account for this. Assuming 2000 is to be shown only once and it appears in the Debit column, is this what you want?
MrExcel_20230619.xlsx
ABCDEFGHIJKLMN
1DATEDESCRIBEDEBITCREDITDATEBANKCASHREC DEBTPR_0000SR_0000PAID PRPAID EXBALANCE
26/13/2023OPENING387,148.006/13/20234,000.0012,000.00103,000.005,000.000.003,000.000.0079,000.00
36/13/2023PR_0000232,000.006/14/20230.000.000.009,000.003,000.000.0030,000.00-39,000.00
46/13/2023PR_0000243,000.006/15/20230.008,200.000.0014,060.000.000.000.00-22,260.00
56/13/2023CASH10,000.00 0.000.000.000.000.000.000.000.00
66/13/2023PAID PR2,000.00TOTAL4,000.0020,200.00103,000.0028,060.003,000.003,000.0030,000.0045,800.00
76/13/2023PAID PR1,000.00
86/13/2023REC DEBT100,000.00
96/13/2023REC DEBT3,000.00
106/13/2023CASH2,000.00
116/13/2023BANK3,000.00
126/13/2023BANK1,000.00
136/14/2023PR_0000252,000.00
146/14/2023SR_000023331,000.00
156/14/2023SR_000023342,000.00
166/14/2023PAID EX10,000.00
176/14/2023PAID EX20,000.00
186/14/2023PR_0000263,000.00
196/14/2023PR_0000274,000.00
206/15/2023CASH1,200.00
216/15/2023CASH7,000.00
226/15/2023PR_00002814,060.00
RAB_1
Cell Formulas
RangeFormula
G2:M5G2=SUMPRODUCT($D$2:$D$22+$C$2:$C$22,($A$2:$A$22=$F2)*(LEFT($B$2:$B$22,LEN(G$1))=G$1))
N2:N5N2=I2-SUM(G2,H2,J2,L2,M2)
G6:M6G6=SUM(G2:G5)
N6N6=I6-SUM(G6,H6,L6,M6)
F2:F5F2=IFERROR(INDEX($A$2:$A$22, MATCH(0,INDEX(COUNTIF($F$1:F1, $A$2:$A$22),0,0),0)),"")

I still do not understand why the column J values appear in the Balance sums on the right side of the table, but column J is omitted in the final Balance in the lower right of the table.
 
Upvote 0
to answer your questions .
I just copy random data without see if the account principle is correct or not , just give example what I want to merging for each item in DEBIT or credit . I can understand your last line and modifying if the calculation is wrong
the idea how merge as I give in OP , shouldn't show minus value .
 
Upvote 0
Please have a look at my post #6 and tell me if it works okay for you. Regardless of whether you have used random data, that still does not explain how you obtained 3000.00 for PAID PR on 13/06/2023 when your source data consists of two debits of 2000 and 1000, and one credit of 2000.
 
Upvote 0
Please have a look at my post #6 and tell me if it works okay for you
yes seem to be good .
that still does not explain how you obtained 3000.00 for PAID PR on 13/06/2023 when your source data consists of two debits of 2000 and 1000, and one credit of 2000.
sorry this is my bad !🙏
should not be in credit .
the common rule is just values in one column (DEBIT OR CREDIT) not two both together.
 
Upvote 0
Thanks for the explanation. I’m glad it’s working for you.
 
Upvote 0

Forum statistics

Threads
1,215,375
Messages
6,124,588
Members
449,174
Latest member
chandan4057

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