Very complicated SUMPRODUCT formula

zookeepertx

Well-known Member
Joined
May 27, 2011
Messages
568
Office Version
  1. 365
Platform
  1. Windows
Hello all!

I have been struggling with this ridiculous formula for longer than I even want to admit, so now I'm here begging for help.
I'll try to explain this as clearly as I can:

What I have to work with:

  • Sheet 1 is called "Totals"
  • Sheet 2 is called "COMPLETE"
  • Totals has a table on it where data from COMPLETE needs to be organized. The table is B4:N10.
  • On Totals the year is in C2 and the months - from AUG-JUL - are in C3-N3.
  • On Totals, O2 contains a formula that gives the last row number on COMPLETE that contains data. Also, there will be a varying number of rows at any given time as data is added or deleted.
  • On COMPLETE, the columns we're concerned with are A, F, L and Q.
  • Column A contains a date which could be varying months, date or year and is formatted as mm/dd/yyyy
  • The other columns are just varying data

What I'm trying to do:

  • On Totals, from C4-N4 counts how many rows on COMPLETE>column A are within the month and year from combining Totals C3-N3.
    • I have this working with this formula: SUM(IF(TEXT(INDIRECT("COMPLETE!$A$2:$A$"&$O$2),"MM/YYYY")=("0" & (MONTH(C$3&1))&"/"&$C2),1,0))
  • ALL other formulas will relate to only the rows on COMPLETE where A is for the particular month. (C5 refers to the month represented by C3/C2 = 08/2017).
  • So, C5 only involves rows on COMPLETE where A = any day in 08/2017.
    • It needs to count how many of those rows have "ALLOCATION" in column F on COMPLETE.
  • So, D5 only involves rows on COMPLETE where A = any day in 09/2017.
    • It needs to count how many of those rows have "ALLOCATION" in column F on COMPLETE...
    • I have this working with this formula: SUMPRODUCT(--(IF(TEXT(INDIRECT("COMPLETE!$A$2:$A$"&$O$2),"MM/YYYY")=("0"&(MONTH(C$3&1))&"/"&$C$2),1,0))*(INDIRECT("COMPLETE!$F$2:$F$"&$O$2)="ALLOCATION"))
  • Now, the first problem -
    • Here's what C6 on Totals needs to count on COMPLETE:
    • If Q is NOT the word YES and is NOT blank
    • If L is either the word NO or is colored red, but has NOT already been counted because of the data in Q
    • I do NOT have this working with this formula: SUMPRODUCT(--(IF(TEXT(INDIRECT("COMPLETE!$A$2:$A$"&$O$2),"MM/YYYY")=("0"&(MONTH(C$3&1))&"/"&$C$2),1,0))*(--(IF(NOT(TEXT(INDIRECT("COMPLETE!$Q$2:$Q$"&$O$2),"@")="YES"),1,0)*((--(IF(NOT(TEXT(INDIRECT("COMPLETE!$L$2:$L$"&$O$2),"@")="NO"),1,0)))))))
    • SORRY! THIS NEXT PART SHOULD BE AT THE LEFT MARGIN BECAUSE IT'S SEPARATE FROM C6 BUT I CAN'T SEEM TO EDIT THAT.
    • C7 on Totals needs to count the rows on COMPLETE where F is "GLC Not Loaded".
      • I have this working with this formula: SUMPRODUCT(--(IF(TEXT(INDIRECT("COMPLETE!$A$2:$A$"&$O$2),"MM/YYYY")=("0"&(MONTH(C$3&1))&"/"&$C$2),1,0))*(INDIRECT("COMPLETE!$F$2:$F$"&$O$2)="GLC NOT LOADED"))
  • Second problem -
    • Here's what C8 on Totals needs to count on COMPLETE:
      • Any rows where F says "DOMESTIC/LANDED" or "WRONG SUPPLIER SITE".
    • Here's what C9 on Totals needs to count on COMPLETE:
      • Any rows that have not already been counted in F.

That's all there is to it! ;) (I do realize this is insane, but then, I work for crazy people, so there's that...)

I included the formulas that I currently have working so that, if you see that there's an easier way you can tell me and so that you can see what's there now in case that helps you to visualize this mess, LOL!

Can all of this even be done? The co-worker originally thought about a macro, but I got to thinking that having dynamic formulas on the Totals sheet would have the workbook be up to the minute at all times. If it would be easier with a macro, that's fine, too.

Thank you for even reading this novel!

Jenny
 
Last edited:

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
a picture is worth a thousand words... can you please copy/paste a sample of your tables/data showing before results and after results (what you want it to look like)?
 
Upvote 0
Okay, I'll give it a shot. Sometimes the board likes to fight with me, LOL!

I'm including the row numbers and column letters (the ones that border the spreadsheet, just to make it easier to reference them.

Here is a sample of the data on the sheet "COMPLETE": (I've taken out most of the data, leaving just the pertinent information, to make it easier to read). I can't seem to make cell backgrounds red on the table, so the ones where the font is red represent that cell being red.

ABCDEFGHIJKLMNOPQRSTUVW
1APPROVE DATEPO #ORDER TYPEON EDI?RMS - BOTH EDI & IMPORT FLAG?
208/01/17GLC NOT LOADEDYESEDI
308/01/17ALLOCATIONNOYES
409/03/17ALLOCATIONYESYES
508/01/18GLC NOT LOADEDYESYES
608/03/17DOMESTIC/LANDED100058327010
709/03/17IMPORT ORDERYESYES
809/03/17ALLOCATIONYESYES
908/01/17WRONG SUPPLIERNOYES
1009/03/17DOMESTIC/LANDEDYESYES
1109/03/17GLC NOT LOADEDYESYES
1210/03/17ALLOCATIONYESYES
1309/03/17ALLOCATIONNONO
14
1508/01/17GLC NOT LOADEDYESYES
16
17
18
1908/01/17ALLOCATIONNOYES
2009/03/18DOMESTIC/LANDEDYESYES
2108/01/17ALLOCATIONYES

<tbody>
</tbody>



Here is how the "Totals" sheet needs to look; I'm only putting in the first few columns of results, to save space. I've included some explanatory information for how the results are calculated.
Column A shows the formulas that are in the results cells for each row. Column B has the criteria for that row, followed by the text in the cell on the spreadsheet. Column C, row 6 shows how the count in that cell was counted, given the data on COMPLETE.

ABCDE
1ROWS 5 AND 20 ON COMPLETE DON'T GET COUNTED AT ALL BECAUSE THEY ARE IN 2018
22017
3AUGSEPOCT
4SUM(IF(TEXT(INDIRECT("COMPLETE!$A$2:$A$"&$O$2),"MM/YYYY")=("0" & (MONTH(C$3&1))&"/"&$C2),1,0))(Total rows on COMPLETE for the month indicated)

Total Approved Import Purchase Orders
761
5SUMPRODUCT(--(IF(TEXT(INDIRECT("COMPLETE!$A$2:$A$"&$O$2),"MM/YYYY")=("0"&(MONTH(C$3&1))&"/"&$C$2),1,0))*(INDIRECT("COMPLETE!$F$2:$F$"&$O$2)="ALLOCATION"))(ALLOCATION in F for the month indicated)

Purchase Orders not Allocated
331
6SUMPRODUCT(--(IF(TEXT(INDIRECT("COMPLETE!$A$2:$A$"&$O$2),"MM/YYYY")=("0"&(MONTH(C$3&1))&"/"&$C$2),1,0))*((--(IF(NOT(TEXT(INDIRECT("COMPLETE!$Q$2:$Q$"&$O$2),"@")="YES"),1,0)*(IF((TEXT(INDIRECT("COMPLETE!$L$2:$L$"&$O$2),"@")="NO"),1,0))))))
(Not YES in Q ; Not BLANK in Q; NO or red color in L if not YES or blank in Q)
THIS FORMULA IS ONLY WORKING FOR THE DATA IN Q. I CAN'T FIGURE OUT HOW TO INCLUDE THE DATA IN L
PO not Flagged Correctly (BULK,Import,EDI)

<tbody>
</tbody>
2 cells in Q that aren't YES or blank. 3 cells in L that are NO and 1 cell that's red (even though it says YES)
6
1 cell in Q that's not YES or blank. 1 cell in L that's NO, but it doesn't get counted because that row already got counted because of Q
1
Q only has 1 cell and it says YES, so not counted. But the cell in L is colored red, so it does get counted
1
7SUMPRODUCT(--(IF(TEXT(INDIRECT("COMPLETE!$A$2:$A$"&$O$2),"MM/YYYY")=("0"&(MONTH(C$3&1))&"/"&$C$2),1,0))*(INDIRECT("COMPLETE!$F$2:$F$"&$O$2)="GLC NOT LOADED"))(GLC NOT LOADED in F)

GLC Not Loaded
110
8SUMPRODUCT(--(IF(TEXT(INDIRECT("COMPLETE!$A$2:$A$"&$O$2),"MM/YYYY")=("0"&(MONTH(C$3&1))&"/"&$C$2),1,0))*((--(IF((TEXT(INDIRECT("COMPLETE!$F$2:$F$"&$O$2),"@")="DOMESTIC"),1,0)+(IF((TEXT(INDIRECT("COMPLETE!$F$2:$F$"&$O$2),"@")="WRONG SUPPLIER"),1,0))))))(DOMESTIC/LANDED or WRONG SUPPLIER in F)

Incorrect Supplier Site/ Landed Vendor
210
9Miscellaneous
10New Vendor

<tbody>
</tbody>


I am absolutely the WORST at trying to explain things, so I hope this makes sense. (I forget just how bad I AM at explaining until I try to do it, then I wonder how anybody understands ANYTHING I'm trying to say. :()

Thank you for looking at this!

Jenny
 
Last edited:
Upvote 0
Sometimes the board likes to fight with me, LOL!

(It just occurred to me that might have sounded wrong. I didn't mean that the PEOPLE on the board like to fight with me; I meant the board itself! Just like the ACTUAL internet - it hates me! LOL!
The PEOPLE on the board are wonderful!)
 
Last edited:
Upvote 0
The best way is to create a small sample (input) along with the desire output (with no formulas).

I don't see any way to attach a workbook or sheet to a message. Am I just missing it somehow when I go to post? Since this is at work, I don't think I'd be allowed to upload a workbook to a "sharing" website. And I'm finding the tables that can be created within a message to not be very friendly (at least, not to me. But that's probably more of a statement on ME than anything else)

I'm starting to think I may have to give up on this being a dynamic table and just do this with a macro. I'd hoped to be able to have it showing the correct information all the time, without having to run a macro. I'm afraid I may have to surrender, in which case, I'm sure I'll need help writing the macro, LOL!

I have to get out of here in a few minutes, but I'll be back to revisit this on Monday.

Thanks

Jenny
 
Upvote 0
After working through your list of requirements, and your tables, I think we can probably come up with some formulas for you, and probably improve a bit on the ones you already have. HOWEVER, the monkey wrench in the works is your requirement in C6 to count cells colored red. A formula cannot detect coloring of a cell. How are those cells colored? If by Conditional Formatting, we can probably duplicate the rule that CF uses in the formulas. If they are manually colored, we can't use native Excel formulas.

Option 1 is to come up with some kind of helper column, where the user puts an X into a cell instead of, or in addition to, coloring the L cell red. Then we can look for the X.

Option 2 is to write a UDF (User-Defined Function), which can detect coloring. We'd need to know the shade of red to look for, or maybe just anything that isn't the default background color.

Option 3 is to write a VBA macro that performs all the calculations at a time. Possibly the easiest way would be to set up an event handler that triggers whenever you select the "Totals" sheet. Depending on how the data is entered in the "COMPLETE" sheet, the totals would always be up to date when you look at them.

Let us know if any of those options sound workable.
 
Upvote 0

Forum statistics

Threads
1,214,646
Messages
6,120,717
Members
448,985
Latest member
chocbudda

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