How To Sum A Column Against Each Unique ID With Multiple Conditions

kashif.special2005

Active Member
Joined
Oct 26, 2009
Messages
443
Hi,

I have a sample data as below, original data is around 90 thousand.

Please Note:- That in the below sample data the value in the column "Approval Status" is show "Approved", but this is not the case it can be other values as well for example like "Rejected" or "Submitted" etc.,

Sample Data:-

IDCategoryNumber of HoursApproval Status
69033154Training8Approved
69033154Revenue8Approved
69033154Training4Approved
69033154Business Support4Approved
69033154Business Support4Approved
69033154Business Support4Approved
69033154Sales Sales Support8Approved
69033154Revenue4Approved
69033154Sales Sales Support8Approved
69033154Sales Sales Support8Approved
69033154Sales Sales Support8Approved
69033154Sales Sales Support8Approved
69033154Sales Sales Support8Approved
69033154Revenue4Approved
69033154Absence8Approved
69033154Revenue8Approved
69033154Revenue8Approved
69033154Revenue4Approved
69033154Business Support4Approved
69033154Business Support4Approved
69033154Revenue8Approved
69033154Revenue8Approved
69033154Revenue8Approved
69033154Revenue8Approved
69033154Revenue4Approved
69033154Standard Hours0Approved


<colgroup><col><col><col><col></colgroup><tbody>
</tbody>

And I want to create the output as below for each unique ID's, below is the sample for 1 ID's

Desired Output.

IDCPARPPARHBARODARCPAR + PPARHBAR:Absence
69033154724820121208

<colgroup><col><col><col><col><col><col><col></colgroup><tbody>
</tbody>


Conditions For Calculating the columns "CPA, PPAR, HBAR, ODAR, CPAR + PPAR And HBAR:Absence"


Condition(1) - CPAR (Column):- Calculating Condition

if column "Approval Status=Approved" and column "Category=Revenue, or Category=Cost
Recovery" then take the sum of column "Number of Hours" and put the value in the column
B against the ID.


Condition(2) - PPAR (Column):- Calculating Condition

if column "Approval Status=Approved" and column "Category=Sales Sales Support" then
take the sum of column "Number of Hours" and put the value in the column C against the ID.


Condition(3) - ODAR (Column):- Calculating Condition

if column "Approval Status=Approved" and column "Category=Training" then take the sum of
column "Number of Hours" and put the value in the column E against the ID.


Condition(4) - HBAR (Column):- Calculating Condition

if Above conditions (1, 2 And 3) are not meet and column "Approval Status<>Approved" and
column "Category<>Absence" then take the sum of column "Number of Hours" and put the
value in the column D against the D.


Condition(5) - HBAR:Absence (Column):- Calculating Condition

if Above all three condition (1, 2 And 3) are not meet and column "Approval
Status=Approved" and column "Category=Absence" then take the sum of column "Number of
Hours" and put the value in the column G against the ID.


Condition(6) - CPAR + PPAR (Column):- Calculating Condition

Simply put the sum of column B (CPAR) + Column C (PPAR)


I don't have any idea how can I achieve desired result, my head is spinning to think about that.

Kindly request to all of excel vba champs, please help me to achieve this task.

Many thanks in advance

Thanks
Kashif
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
F​
G​
H​
I​
J​
K​
L​
M​
1​
ID
CPAR
PPAR
HBAR
ODAR
CPAR+PPAR
HBAR:Absence
2​
69033154​
72​
48​
0​
12​
120​
???​
G2: =SUM(SUMIFS($C$2:$C$27, $A$2:$A$27, $F2, $B$2:$B$27, {"Revenue","Cost Recovery"}, $D$2:$D$27, "Approved"))
3​
H2: =SUMIFS($C$2:$C$27, $A$2:$A$27, $F2, $B$2:$B$27, "Sales Sales Support", $D$2:$D$27, "Approved")
4​
I2: =SUMIFS($C$2:$C$27, $A$2:$A$27, $F2, $B$2:$B$27, "<>Absence", $D$2:$D$27, "<>Approved")
5​
J2: =SUMIFS($C$2:$C$27, $A$2:$A$27, $F2, $B$2:$B$27, "Training", $D$2:$D$27, "Approved")
6​
K2: =G2+H2
 
Upvote 0
Hi shg,

Thank you thank you so much for reply.

For column HBAR:Absence the calculation method is

if the conditions 1, 2 And 3 are not meet and the column "Approval
Status=Approved" and column "Category=Absence" then take the sum of column "Number of
Hours" and put the value in the column G against the ID.

The value for the column "HBAR" is showing 0, however as per the data the HBAR value should be 20, and for the column HBAR:Absence value should be 8.

For HBAR:- The category should not be "Absence" and
Approval Status should not be "Approved"

in the conditions 1, 2 and 3 we have not used the value in the columns category "Business Support", so for HBAR this value will sum for the column "HBAR"


Or you can say that

Condition(4) - HBAR (Column):- Calculating Condition

if Above conditions (1, 2 And 3) are not meet the take the sum of column "Number of Hours" and put the value in the column D against the D.


And I have one request as well can we don't do with VBA because for this first I have to copy the unique ID in columns A, and in the formula you are using the column positions as fixed like for ID column you are considering column A, but in the future the columns positions may change.

So I am requesting you can we do this VBA?

Thanks
Kashif
 
Last edited:
Upvote 0
Condition(4) - HBAR (Column):- Calculating Condition

if Above conditions (1, 2 And 3) are not meet the take the sum of column "Number of Hours" and put the value in the column D against the ID.
 
Upvote 0
Hi All,

I have Added a sample column "Manually Putting Conditional Values For Understanding" in the end for better understanding.


IDCategoryNumber of HoursApproval StatusManually Putting Conditional Values For Understanding
69033154Training8ApprovedODAR
69033154Revenue8ApprovedCPAR
69033154Training4ApprovedODAR
69033154Business Support4ApprovedHBAR
69033154Business Support4ApprovedHBAR
69033154Business Support4ApprovedHBAR
69033154Sales Sales Support8ApprovedPPAR
69033154Revenue4ApprovedCPAR
69033154Sales Sales Support8ApprovedPPAR
69033154Sales Sales Support8ApprovedPPAR
69033154Sales Sales Support8ApprovedPPAR
69033154Sales Sales Support8ApprovedPPAR
69033154Sales Sales Support8ApprovedPPAR
69033154Revenue4ApprovedCPAR
69033154Absence8ApprovedHBAR:Absence
69033154Revenue8ApprovedCPAR
69033154Revenue8ApprovedCPAR
69033154Revenue4ApprovedCPAR
69033154Business Support4ApprovedHBAR
69033154Business Support4ApprovedHBAR
69033154Revenue8ApprovedCPAR
69033154Revenue8ApprovedCPAR
69033154Revenue8ApprovedCPAR
69033154Revenue8ApprovedCPAR
69033154Revenue4ApprovedCPAR
69033154Standard Hours0ApprovedHBAR

<tbody>
</tbody>

I putted those value as per the below conditions

Condition(1) - CPAR (Column):- Calculating Condition

if column "Approval Status=Approved" and column "Category=Revenue, or Category=Cost
Recovery" then it will be
CPAR.


Condition(2) - PPAR (Column):- Calculating Condition

if column "Approval Status=Approved" and column "Category=Sales Sales Support"
then it will be PPAR.


Condition(3) - ODAR (Column):- Calculating Condition

if column "Approval Status=Approved" and column "Category=Training"
then it will be ODAR.

Condition(4) - HBAR (Column):- Calculating Condition

If above conditions (1, 2 and 3) are not met then HBAR and in the HBAR Staus if
"Approval Status=Approved" and column "Category=Absence" then then HBAR:Absence

I hope it will help to understand better.
 
Last edited:
Upvote 0
Hi,

Please all excel experts please help me to solve this problem.

I google for VBA code but I could not find anything as per my requirement, I saw similar kind of problem solved the VBA Dictionary, but I don't know how to use Dictionary in VBA.

Please help me.


Thanks in advance.

Thanks
Kashif
 
Upvote 0

Forum statistics

Threads
1,214,926
Messages
6,122,305
Members
449,079
Latest member
juggernaut24

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