Computing Monthly Totals with Variations

dwgnome

Active Member
Joined
Dec 18, 2005
Messages
447
Office Version
  1. 2019
Platform
  1. Windows
I have the following table with data

CodeCategoryVx1/1/242/1/243/1/244/1/245/1/24
AT370-3MxPrimer2.1758.5105142.5125147
AM-29711MxTopcoat0.88282410.8208
E61W00753-EXPPrimer2.20275110220220220
F75EXA16707Topcoat1.88275220220275275
E61XXA16720-4366Primer3.46440110165220330
ENGC11131Cleaning Solvent CS-23.38100250700100200
CGC111Cleaning Solvent CS-14.463000100510
ALK-314003Topcoat5.4700010
ALK-000761Topcoat5.3800005
CGC112Cleaning Solvent CS-10.204000000
ENGC0Cleaning Solvent CS-20.19200030000


Current formula for 1/1/24:
'=SUMPRODUCT($C$7:$C$17,(INDEX($D$7:$H$17,,MATCH(A23,$D$6:$H$6,0))))
1/1/244,589
2/1/242,130

While the formula works as designed, I need a way to modify the formula to account for reduction for cleaning solvents:

For any rows having Cleaning Solvent CS-1 (Col B), then multiply the result of those row calculations by 0.1
So for January instead of 4.46*300, it should be 4.46*300*.1

For any rows having Cleaning Solvent CS-2, then multiply the result of those row calculations by 0.5
So for January instead of 3.38*100, it should be 3.38*100*.5

The correct results for 1/1/24 should then be: 3,126
The correct results for 2/1/24 should then be: 1,707

Please note I still use Excel 2019
 
Consider:

Book1
ABCDEFGH
1
2
3
4
5
6CodeCategoryVx1/1/20242/1/20243/1/20244/1/20245/1/2024
7AT370-3MxPrimer2.1758.5105142.5125147
8AM-29711MxTopcoat0.88282410.8208
9E61W00753-EXPPrimer2.2275110220220220
10F75EXA16707Topcoat1.88275220220275275
11E61XXA16720-4366Primer3.46440110165220330
12ENGC11131Cleaning Solvent CS-23.38100250700100200
13CGC111Cleaning Solvent CS-14.463000100510
14ALK-314003Topcoat5.4700010
15ALK-000761Topcoat5.3800005
16CGC112Cleaning Solvent CS-10.24000000
17ENGC0Cleaning Solvent CS-20.19200030000
18
19
20
21
22OriginalVersion1
231/1/20244589.9853125.785
242/1/20242130.171707.67
Sheet4
Cell Formulas
RangeFormula
B23:B24B23=SUMPRODUCT($C$7:$C$17,(INDEX($D$7:$H$17,,MATCH(A23,$D$6:$H$6,0))))
C23:C24C23=SUMPRODUCT($C$7:$C$17*$D$7:$H$17*($D$6:$H$6=A23)*((1+9*ISERROR(SEARCH("Cleaning Solvent CS-1",$B$7:$B$17)))/10)*((1+ISERROR(SEARCH("Cleaning Solvent CS-2",$B$7:$B$17)))/2))


This version should work for you in Excel 2019. It's a bit obtuse though. I tried to find a version that's a bit easier to understand, but I'm running into testing difficulties between our versions. I'll keep plugging at it.
 
Upvote 0
Solution
Hi Eric,

Thank you for that solution as it works.
could you explain how the formula works:
Code:
1+9*ISERROR(SEARCH("Cleaning Solvent CS-1",$B$7:$B$17)))/10)

I think it isolates each instance of "Cleaning Solvent CS-1 and assigns 1/10 or 0.1 to each occurrence. However, when I step through the evaluate formula I cannot understand the purpose of the ISERROR, the #VALUE it creates then converts to 9s etc. Could you explain how that works as I may need to adjust other types of products in the future, such as needing to adjust to other fractions.
 
Upvote 0
Sure. SUMPRODUCT has array processing on by default, unless you have an IF or IFERROR function. So we have to find a way to do a conditional without IF.

(1+9*ISERROR(SEARCH("Cleaning Solvent CS-1",$B$7:$B$17)))/10)

The SEARCH function looks for "Cleaning Solvent CS-1" in every cell in B7:B17, and returns either the offset into the cell where the text begins, or an error if it is not found. The ISERROR checks for the error. If there is an error, meaning not found, then it returns TRUE. Multiply that by 9, and it turns into a 9. Add 1, and you get 10, divide by 10 and you get 1, so the given row is multiplied by 1. If there is not an error, meaning that the text is found, then the ISERROR returns FALSE, multiply that by 9 and you get 0, add 1 and divide by 10 and you get .1, which is multiplied by that row. Kind of convoluted, but it works. The other section for CS-2 works the same. You could just use the "CS-1" or "CS-2" if you want to shorten it a bit, as long as those text snippets don't appear anywhere else.

It is possible to enter the formula with Control+Shift+Enter to enable array processing even with an IF included. So this should theoretically work:

Book1
ABCDEFGHIJK
1
2
3
4
5
6CodeCategoryVx1/1/20242/1/20243/1/20244/1/20245/1/2024CategoryFactor
7AT370-3MxPrimer2.1758.5105142.5125147Cleaning Solvent CS-10.1
8AM-29711MxTopcoat0.88282410.8208Cleaning Solvent CS-20.5
9E61W00753-EXPPrimer2.2275110220220220
10F75EXA16707Topcoat1.88275220220275275
11E61XXA16720-4366Primer3.46440110165220330
12ENGC11131Cleaning Solvent CS-23.38100250700100200
13CGC111Cleaning Solvent CS-14.463000100510
14ALK-314003Topcoat5.4700010
15ALK-000761Topcoat5.3800005
16CGC112Cleaning Solvent CS-10.24000000
17ENGC0Cleaning Solvent CS-20.19200030000
18
19
20
21
22OriginalVersion1Version2
231/1/20244589.9853125.7854589.985
242/1/20242130.171707.672130.17
Sheet4
Cell Formulas
RangeFormula
B23:B24B23=SUMPRODUCT($C$7:$C$17,(INDEX($D$7:$H$17,,MATCH(A23,$D$6:$H$6,0))))
C23:C24C23=SUMPRODUCT($C$7:$C$17*$D$7:$H$17*($D$6:$H$6=A23)*((1+9*ISERROR(SEARCH("Cleaning Solvent CS-1",$B$7:$B$17)))/10)*((1+ISERROR(SEARCH("Cleaning Solvent CS-2",$B$7:$B$17)))/2))
D23:D24D23=SUM($C$7:$C$17*IFERROR(VLOOKUP($C$7:$C$17,$J$7:$K$20,2,0),1)*INDEX($D$7:$H$17,0,MATCH(A23,$D$6:$H$6,0)))
Press CTRL+SHIFT+ENTER to enter array formulas.


But the issue here is that Control+Shift+Enter works differently on versions of Excel after 2021, so my testing does not give the expected answer. You can try the version2 formula, which I think should work for you, but I can't validate that. I think you'll agree it's much simpler to understand and update.
 
Upvote 0
Hi Eric,

Thank you so much for your expertise and explanation of how the ISERROR(SEARCH works. I understand completely.
Also, something I think is pretty cool is that the SEARCH function seems to work for partial word matching without having to use wildcards.
I'll have to experiment with your other idea you presented.
 
Upvote 0
I just noticed that the version2 formula should be:

=SUM($C$7:$C$17*IFERROR(VLOOKUP($B$7:$B$17,$J$7:$K$20,2,0),1)*INDEX($D$7:$H$17,0,MATCH(A24,$D$6:$H$6,0)))

You would still need to use Control+Shift+Enter.
 
Upvote 0

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