Sum multiple columns based on column and row criteria

WardyKSA

New Member
Joined
Nov 1, 2015
Messages
8
Hi all,
I need to be able to sum multiple columns based on the column header (to select the columns) but also particular rows based on the first column.

Please see the below example:
BasicAllowanceBasicTaxBasic
Emp No.SalaryAccomHol PayTaxTemp Sal
150001250850500500
2500005000
3800012500800800
45000125015005000

<tbody>
</tbody>

I want to be able to sum all the Basic columns for employee 1, which should return 6,350.

I'm having a complete mental block and can only think of using multiple vlookups.

Any help would be much appreciated

Thanks
W
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
How many of these basic columns are there in the workbook and are they always in the same position?
 
Upvote 0
Is this too simple (copied down for each row)? If it's not what you are looking for, please add further detail.

=SUMIF(B$1:F$1,"Basic",B3:F3)
 
Upvote 0
Or perhaps this copied down:

=INDEX(SUMIF(B$1:F$1,"Basic",B3:F6),MATCH(A3,A3:A6),0)
 
Upvote 0
Hi Ali,
Currently all the columns should stay in the same place/order, but this could change.

Apologies I probably didn't give enough info originally but basically the table outlined above is a replica of our payroll system report. From this I then create a journal to post all the transactions into the finance system, which needs to be presented as a list.

The journal template looks like this (very simplified):
Currently the formula in the journal template states =if(column C = "Basic",vlookup emp code and return column 2), then again for column 4 and then column 6.

I just want 1 formula which looks up the emp code and returns the sum of columns based on the column header, it sounds so easy!! haha

Emp No.AmountDescription
16350Basic
11250Accom
10Overtime
1500Tax
25000Basic
20Accom
20Overtime
2500Tax
38800Basic
31250Accom

<tbody>
</tbody>


Thanks
W
 
Upvote 0
So which layout are we working with? I provided a solution for the layout in your OP, but now it is presented entirely differently! Please state your case clearly so that respondents aren't wasting their time: currently, I am confused!

EDIT: summing by the column header is easy - see my solution. What isn't entirely clear to me is what you want. Is your latest table how you want the summary data presenting? If so, is there a reason why it has to be separated out into individual rows>
 
Last edited:
Upvote 0
These work:

=INDEX(SUMIF(B$1:F$1,"Basic",B3:F6),MATCH(A3,A3:A6),0)
=INDEX(SUMIF(B$2:F$2,"Accom",B3:F6),MATCH(A3,A3:A6),0)
=INDEX(SUMIF(B$2:F$2,"Tax",B3:F6),MATCH(A3,A3:A6),0)

You will need to tell us how you are calculating overtime.

EDIT: not sure that you have read beyond my first post to this thread!!!
 
Upvote 0
These work:

=INDEX(SUMIF(B$1:F$1,"Basic",B3:F6),MATCH(A3,A3:A6),0)
=INDEX(SUMIF(B$2:F$2,"Accom",B3:F6),MATCH(A3,A3:A6),0)
=INDEX(SUMIF(B$2:F$2,"Tax",B3:F6),MATCH(A3,A3:A6),0)

You will need to tell us how you are calculating overtime.

EDIT: not sure that you have read beyond my first post to this thread!!!


I have seen your above posts! Your index and match formula seems to work for employee 1 for Basic, Tax, Allowance, however when it gets to employee 2 and onwards it #REF!.

Ignore the overtime, I was just trying to replicate in the simplest format what it looks like (In reality the are many columns, not just Basic, Accomodation, Overtime, Tax).

The first table in my OP is the current data set which I am working on. The solution will be used in the second table which is the output. The second table needs to be in the list order unfortunately as this is how the journal is uploaded.

Is there a way to screenshot on this forum and I'll show you exactly the formulas I'm using?

This is the current formula which works on the first table but only for employee 1

=INDEX(SUMIF(B$1:F$1,C10,$B$3:$F$6),MATCH(A10,$A$3:$A$6),0)

C10 is a cell which states Basic
A10 is the employee code
 
Upvote 0
Data Table (From payroll system)
BasicAllowanceBasicTaxBasic
Emp No.SalaryAccomHol PayTaxTemp Sal
150001250850500500
25000 05000
3800012500800800
45000125015005000
Journal Template
Critera 1Formula (Calculated)Critera 2Formula (detail)
16350Basic=INDEX(SUMIF(B$1:F$1,C10,$B$3:$F$6),MATCH(A10,$A$3:$A$6),0)
11250Allowance=INDEX(SUMIF(B$1:F$1,C11,$B$3:$F$6),MATCH(A11,$A$3:$A$6),0)
1500Tax=INDEX(SUMIF(B$1:F$1,C12,$B$3:$F$6),MATCH(A12,$A$3:$A$6),0)
2#REF!Basic=INDEX(SUMIF(B$1:F$1,C13,$B$3:$F$6),MATCH(A13,$A$3:$A$6),0)
2#REF!Allowance=INDEX(SUMIF(B$1:F$1,C14,$B$3:$F$6),MATCH(A14,$A$3:$A$6),0)
2#REF!Tax=INDEX(SUMIF(B$1:F$1,C15,$B$3:$F$6),MATCH(A15,$A$3:$A$6),0)
3#REF!Basic=INDEX(SUMIF(B$1:F$1,C16,$B$3:$F$6),MATCH(A16,$A$3:$A$6),0)
3#REF!Allowance=INDEX(SUMIF(B$1:F$1,C17,$B$3:$F$6),MATCH(A17,$A$3:$A$6),0)
3#REF!Tax=INDEX(SUMIF(B$1:F$1,C18,$B$3:$F$6),MATCH(A18,$A$3:$A$6),0)

<colgroup><col><col><col span="4"><col span="2"></colgroup><tbody>
</tbody>
 
Upvote 0
Is there a way to screenshot on this forum and I'll show you exactly the formulas I'm using?
Read my signature block below.


Try this formula, copied down.

Excel Workbook
ABCDEFG
1BasicAllowanceBasicTaxBasic
2Emp No.SalaryAccomHol PayTaxTemp Sal
3150001250850500500
42500005000
53800012500800800
645000125015005000
7
8
9Critera 1SumCritera 2
1016350Basic
1111250Allowance
121500Tax
1325000Basic
1420Allowance
152500Tax
1638800Basic
1731250Allowance
183800Tax
19
Sum Based on Headings
 
Upvote 0

Forum statistics

Threads
1,216,734
Messages
6,132,418
Members
449,727
Latest member
Aby2024

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