IF Statements For Totals or Pivots

jarett

Board Regular
Joined
Apr 12, 2021
Messages
179
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I am pulling data from MS SQL and I have a few columns that I have to take logic into place in order to get an "add" quantity in a separate column for certain "item code" values. This is my logic that gets the counts, the two columns I need to total are K & L, udf_Qty received- always count if > 0
udf_Qty pulled - count if (allocated = Y and date allocated <> today) or processed incomplete = Y

The goal is to just get a total to display just once, so I am not sure if thats possible or if I would have to add a column to get the count of each row first then add a column after that to get the total? I attached a sample copy of file . The last column labeled "add" would what I want my results to be and displayed like this. Would a pivot work for this?

TEST.xlsx
ABCDEFGHIJKL
1SalesOrderNoItemCodeQuantityOrderedQuantityBackorderedUDF_QTY_PULLEDUDF_QTY_RECEIVEDUDF_PROCESSED_ICUDF_PROCESS_INCOMPLETEUDF_ALLOCATEDWarehouseCodeDATE ALLOCATEDadd
2830444410022328-BEIGE/KHAKI-LGR5050NNY000
3830705610022328-BEIGE/KHAKI-LGR3030NNN000
4830970210022328-BEIGE/KHAKI-LGR5050NNY00010
5824540510022328-BEIGE/KHAKI-MEDR2020NY000
6830971010022328-BEIGE/KHAKI-MEDR3030NNN0002
7826763910022328-BEIGE/KHAKI-SMLR2020NNN0006/16/2023
8829157810022328-BEIGE/KHAKI-SMLR2111NNY0002
9828728110022328-BEIGE/KHAKI-XLR5050NNN000
10830030310022328-BEIGE/KHAKI-XLR1101NNN000
11830747910022328-BEIGE/KHAKI-XLR1010NNY000
12831045710022328-BEIGE/KHAKI-XLR5050NNY0007
13824540510022328-BEIGE/KHAKI-XXLR5050NNY000
14830999010022328-BEIGE/KHAKI-XXLR4040NNN0005
15829839410022328-BEIGE/KHAKI-XXLTR3030YNN0003
Sheet1
Cells with Conditional Formatting
CellConditionCell FormatStop If True
G4Cell ValueduplicatestextNO
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
I don't agree with your results, but is this what you want.
TEST.xlsx
ABCDEFGHIJKL
1SalesOrderNoItemCodeQuantityOrderedQuantityBackorderedUDF_QTY_PULLEDUDF_QTY_RECEIVEDUDF_PROCESSED_ICUDF_PROCESS_INCOMPLETEUDF_ALLOCATEDWarehouseCodeDATE ALLOCATEDadd
2830444410022328-BEIGE/KHAKI-LGR5050NNY000 
3830705610022328-BEIGE/KHAKI-LGR3030NNN000 
4830970210022328-BEIGE/KHAKI-LGR5050NNY00010
5824540510022328-BEIGE/KHAKI-MEDR2020NY000 
6830971010022328-BEIGE/KHAKI-MEDR3030NNN0002
7826763910022328-BEIGE/KHAKI-SMLR2020NNN00016/06/2023 
8829157810022328-BEIGE/KHAKI-SMLR2111NNY0001
9828728110022328-BEIGE/KHAKI-XLR5050NNN000 
10830030310022328-BEIGE/KHAKI-XLR1101NNN000 
11830747910022328-BEIGE/KHAKI-XLR1010NNY000 
12831045710022328-BEIGE/KHAKI-XLR5050NNY0006
13824540510022328-BEIGE/KHAKI-XXLR5050NNY000 
14830999010022328-BEIGE/KHAKI-XXLR4040NNN0005
15829839410022328-BEIGE/KHAKI-XXLTR3030YNN0000
Sheet1
Cell Formulas
RangeFormula
L2:L15L2=IF(COUNTIFS(B$2:B2,B2)=COUNTIFS(B:B,B2),SUMIFS(E:E,B:B,B2,I:I,"Y",K:K,"<>"&TODAY(),H:H,"<>Y"),"")
Cells with Conditional Formatting
CellConditionCell FormatStop If True
G4Cell ValueduplicatestextNO
 
Upvote 0
I don't agree with your results, but is this what you want.
TEST.xlsx
ABCDEFGHIJKL
1SalesOrderNoItemCodeQuantityOrderedQuantityBackorderedUDF_QTY_PULLEDUDF_QTY_RECEIVEDUDF_PROCESSED_ICUDF_PROCESS_INCOMPLETEUDF_ALLOCATEDWarehouseCodeDATE ALLOCATEDadd
2830444410022328-BEIGE/KHAKI-LGR5050NNY000 
3830705610022328-BEIGE/KHAKI-LGR3030NNN000 
4830970210022328-BEIGE/KHAKI-LGR5050NNY00010
5824540510022328-BEIGE/KHAKI-MEDR2020NY000 
6830971010022328-BEIGE/KHAKI-MEDR3030NNN0002
7826763910022328-BEIGE/KHAKI-SMLR2020NNN00016/06/2023 
8829157810022328-BEIGE/KHAKI-SMLR2111NNY0001
9828728110022328-BEIGE/KHAKI-XLR5050NNN000 
10830030310022328-BEIGE/KHAKI-XLR1101NNN000 
11830747910022328-BEIGE/KHAKI-XLR1010NNY000 
12831045710022328-BEIGE/KHAKI-XLR5050NNY0006
13824540510022328-BEIGE/KHAKI-XXLR5050NNY000 
14830999010022328-BEIGE/KHAKI-XXLR4040NNN0005
15829839410022328-BEIGE/KHAKI-XXLTR3030YNN0000
Sheet1
Cell Formulas
RangeFormula
L2:L15L2=IF(COUNTIFS(B$2:B2,B2)=COUNTIFS(B:B,B2),SUMIFS(E:E,B:B,B2,I:I,"Y",K:K,"<>"&TODAY(),H:H,"<>Y"),"")
Cells with Conditional Formatting
CellConditionCell FormatStop If True
G4Cell ValueduplicatestextNO
Do you not agree because the results from the formula are not what I listed them to be?
 
Upvote 0
Perhaps this:

Excel Formula:
=IF(B2<>B3,SUMIF(B$2:B2,B2,F$2:F2)+SUMIFS(E$2:E2,K$2:K2,"<>"&TODAY(),I$2:I2,"Y",B$2:B2,B2)+SUMIFS(E$2:E2,G$2:G2,"Y",B$2:B2,B2),"")

It assumes the data is sorted on column B.
 
Upvote 0
Do you not agree because the results from the formula are not what I listed them to be?
Yes, so I don't know if I've misunderstood, or if your results are wrong.
 
Upvote 0
Perhaps this:

Excel Formula:
=IF(B2<>B3,SUMIF(B$2:B2,B2,F$2:F2)+SUMIFS(E$2:E2,K$2:K2,"<>"&TODAY(),I$2:I2,"Y",B$2:B2,B2)+SUMIFS(E$2:E2,G$2:G2,"Y",B$2:B2,B2),"")

It assumes the data is sorted on column B.
It looks good however I found an inconsistency, sometimes we will have column G and column I both = Y, but I do not want to count it twice. I am thinking that is what happened here, highlighted in yellow.
Book1
ABCDEFGHIJKLM
1SalesOrderNoItemCodeQuantityOrderedQuantityBackorderedUDF_QTY_PULLEDUDF_QTY_RECEIVEDUDF_PROCESSED_ICUDF_PROCESS_INCOMPLETEUDF_ALLOCATEDWarehouseCodeUDF_DATE_ALLOCATEDColumn1Should be
2000261410012552-BLUE-30301010NNY0004/19/2023 0:001
3824661110012552-BLUE-30301010YNY0005/30/2023 0:003
4825025310012552-BLUE-30302020NY0005/2/2023 0:005
5827802910012552-BLUE-30302020NNN000#####################5
6830670710012552-BLUE-30304040NNN0005
7830832710012552-BLUE-30302020NNY0006/13/2023 0:0076
8830444410012552-BLUE-3032130130NNY0006/16/2023 0:0013
9831068510012552-BLUE-3032100100NNY0006/16/2023 0:002323
10000221410012552-BLUE-3034-50-50NNN000#####################0
11826760310012552-BLUE-30342020NNY0006/15/2023 0:002
12830879310012552-BLUE-30341010NNN00022
13830889210012552-BLUE-30361010NNN00000
Sheet1
 
Upvote 0
If the only issue with RoryA's formula is that it returned a 3 instead of a 2, the following bolded addition to the formula on Cell L2 should resolve the issue of duplicate "Y" in Columns G & I - assuming data is sorted on Column B.
=IF(B2<>B3,SUMIF(B$2:B2,B2,F$2:F2)+SUMIFS(E$2:E2,K$2:K2,"<>"&TODAY(),I$2:I2,"Y",B$2:B2,B2)+SUMIFS(E$2:E2,G$2:G2,"Y",B$2:B2,B2,I$2:I2,"<>Y"),"")
 
Last edited:
Upvote 0
Solution
If the only issue with RoryA's formula is that it returned a 3 instead of a 2, the following bolded addition to the formula on Cell L2 should resolve the issue of duplicate "Y" in Columns G & I - assuming data is sorted on Column B.
=IF(B2<>B3,SUMIF(B$2:B2,B2,F$2:F2)+SUMIFS(E$2:E2,K$2:K2,"<>"&TODAY(),I$2:I2,"Y",B$2:B2,B2)+SUMIFS(E$2:E2,G$2:G2,"Y",B$2:B2,B2,I$2:I2,"<>Y"),"")
That worked! Thanks to everyone!
 
Upvote 0

Forum statistics

Threads
1,223,907
Messages
6,175,301
Members
452,633
Latest member
DougMo

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