SOLVED

Help with multiple conditional statements in Excel

%3CLINGO-SUB%20id%3D%22lingo-sub-2383382%22%20slang%3D%22en-US%22%3EHelp%20with%20multiple%20conditional%20statements%20in%20Excel%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2383382%22%20slang%3D%22en-US%22%3E%3CP%3E%3CSPAN%3EBelow%20is%20an%20example%20of%20a%20much%20larger%20dataset%20that%20I%20am%20working%20with.%20What%20I%20am%20having%20trouble%20figuring%20out%20is%20how%20to%20write%20a%20formula%20that%20does%20the%20following%3A%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%3COL%3E%3CLI%3E%3CSPAN%3EFind%20a%20certain%20%E2%80%9CVendor%20Name%E2%80%9D%20in%20column%20A.%26nbsp%3B%3C%2FSPAN%3E%3C%2FLI%3E%3CLI%3E%3CSPAN%3EBased%20on%20the%20%E2%80%9CVendor%20Name%E2%80%9D%20selected%20in%20column%20A%2C%20determine%20the%20highest%20%E2%80%9CTotal%E2%80%9D%20in%20column%20D.%26nbsp%3B%3C%2FSPAN%3E%3C%2FLI%3E%3CLI%3E%3CSPAN%3EBased%20on%20the%20highest%20%E2%80%9CTotal%E2%80%9D%20in%20column%20D%20find%20the%20respective%20%E2%80%9CRule%E2%80%9D%20in%20column%20E.%26nbsp%3B%3C%2FSPAN%3E%3C%2FLI%3E%3C%2FOL%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22gtsmith2_0-1621945573465.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F283482i2B57AEF8A94CEC2A%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22gtsmith2_0-1621945573465.png%22%20alt%3D%22gtsmith2_0-1621945573465.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2383382%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EFormulas%20and%20Functions%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2383541%22%20slang%3D%22en-US%22%3ERe%3A%20Help%20with%20multiple%20conditional%20statements%20in%20Excel%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2383541%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1062585%22%20target%3D%22_blank%22%3E%40gtsmith2%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ELet's%20say%20the%20vendor%20name%20you're%20looking%20for%20is%20in%20cell%20G2.%3C%2FP%3E%0A%3CP%3EThe%20rule%20you%20want%20is%20returned%20by%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3DINDEX(%24E%242%3A%24E%24200%2C%20MATCH(1%2C%20INDEX((%24A%242%3A%24A%24200%3DG2)*(%24D%242%3A%24D%24200%3DMAXIFS(%24D%242%3A%24D%24200%2C%20%24A%242%3A%24A%24200%2C%20G2))%2C%20%2C%20)%2C%200))%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAdjust%20the%20ranges%20if%20needed.%20the%20formula%20can%20be%20filled%20down%20if%20you%20have%20other%20vendor%20names%20in%20G3%2C%20G4%20etc.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2383618%22%20slang%3D%22en-US%22%3ERe%3A%20Help%20with%20multiple%20conditional%20statements%20in%20Excel%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2383618%22%20slang%3D%22en-US%22%3EI%20don't%20seem%20to%20have%20the%20MAXIFS%20function%20in%20my%20version%20of%20Excel.%20Is%20there%20any%20way%20to%20use%20the%20AGGREGATE%20function%20in%20place%20of%20the%20MAXIFS%20function%3F%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2383725%22%20slang%3D%22en-US%22%3ERe%3A%20Help%20with%20multiple%20conditional%20statements%20in%20Excel%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2383725%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1062585%22%20target%3D%22_blank%22%3E%40gtsmith2%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ETry%20the%20following%20array%20formula%2C%20confirmed%20with%20Ctrl%2BShift%2BEnter%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3DINDEX(%24E%242%3A%24E%24200%2C%20MATCH(1%2C%20(%24A%242%3A%24A%24200%3DG2)*(%24D%242%3A%24D%24200%3DMAX(IF(%24A%242%3A%24A%24200%3DG2%2C%20%24D%242%3A%24D%24200)))%2C%200))%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2385094%22%20slang%3D%22en-US%22%3ERe%3A%20Help%20with%20multiple%20conditional%20statements%20in%20Excel%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2385094%22%20slang%3D%22en-US%22%3EThis%20works%20great.%20Would%20you%20know%20a%20way%20to%20update%20this%20to%20also%20filter%20out%20any%20%22Rule%22%20that%20equals%20zero%3F%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2385096%22%20slang%3D%22en-US%22%3ERe%3A%20Help%20with%20multiple%20conditional%20statements%20in%20Excel%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2385096%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1062585%22%20target%3D%22_blank%22%3E%40gtsmith2%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIn%20your%20screenshot%2C%20the%20rules%20are%20text%20values.%20How%20would%20they%20be%20zero%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2385152%22%20slang%3D%22en-US%22%3ERe%3A%20Help%20with%20multiple%20conditional%20statements%20in%20Excel%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2385152%22%20slang%3D%22en-US%22%3ESorry%20I%20should%20have%20been%20more%20thorough%20in%20the%20example.%20There%20are%20some%20%22Rules%22%20that%20are%20blank%20in%20my%20actual%20data%20set%20that%20appear%20as%20zero%20when%20I%20run%20your%20formula.%20Does%20that%20make%20sense%3F%3CBR%20%2F%3E%3CBR%20%2F%3EAlso%2C%20do%20you%20know%20a%20way%20that%20this%20formula%20could%20be%20modified%20to%20calculate%20the%202nd%2C%203rd%2C%204th%20and%205th%20%22Rule%22%20with%20the%20highest%20%22Total%22%3F%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2385170%22%20slang%3D%22en-US%22%3ERe%3A%20Help%20with%20multiple%20conditional%20statements%20in%20Excel%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2385170%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1062585%22%20target%3D%22_blank%22%3E%40gtsmith2%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ETo%20exclude%20empty%20rules%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3DINDEX(%24E%242%3A%24E%24200%2C%20MATCH(1%2C%20(%24E%242%3A%24E%24200%26lt%3B%26gt%3B%22%22)*(%24A%242%3A%24A%24200%3DG2)*(%24D%242%3A%24D%24200%3DMAX(IF((%24E%242%3A%24E%24200%26lt%3B%26gt%3B%22%22)*(%24A%242%3A%24A%24200%3DG2)%2C%20%24D%242%3A%24D%24200)))%2C%200))%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3Eagain%20confirmed%20with%20Ctrl%2BShift%2BEnter.%3C%2FP%3E%0A%3CP%3EI'll%20have%20to%20think%20about%20your%20other%20question.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2385392%22%20slang%3D%22en-US%22%3ERe%3A%20Help%20with%20multiple%20conditional%20statements%20in%20Excel%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2385392%22%20slang%3D%22en-US%22%3EThank%20you%20so%20much!%3CBR%20%2F%3ERegarding%20my%20second%20question%20I'm%20thinking%20that%20the%20AGGREGATE%20function%20might%20work%20but%20I%20have%20not%20had%20any%20luck%20with%20it.%3C%2FLINGO-BODY%3E
Occasional Contributor

Below is an example of a much larger dataset that I am working with. What I am having trouble figuring out is how to write a formula that does the following: 

  1. Find a certain “Vendor Name” in column A. 
  2. Based on the “Vendor Name” selected in column A, determine the highest “Total” in column D. 
  3. Based on the highest “Total” in column D find the respective “Rule” in column E. 

 

gtsmith2_0-1621945573465.png

 

 

17 Replies

@gtsmith2 

Let's say the vendor name you're looking for is in cell G2.

The rule you want is returned by

 

=INDEX($E$2:$E$200, MATCH(1, INDEX(($A$2:$A$200=G2)*($D$2:$D$200=MAXIFS($D$2:$D$200, $A$2:$A$200, G2)), , ), 0))

 

Adjust the ranges if needed. the formula can be filled down if you have other vendor names in G3, G4 etc.

I don't seem to have the MAXIFS function in my version of Excel. Is there any way to use the AGGREGATE function in place of the MAXIFS function?

@gtsmith2 

Try the following array formula, confirmed with Ctrl+Shift+Enter:

 

=INDEX($E$2:$E$200, MATCH(1, ($A$2:$A$200=G2)*($D$2:$D$200=MAX(IF($A$2:$A$200=G2, $D$2:$D$200))), 0))

This works great. Would you know a way to update this to also filter out any "Rule" that equals zero?

@gtsmith2 

In your screenshot, the rules are text values. How would they be zero?

Sorry I should have been more thorough in the example. There are some "Rules" that are blank in my actual data set that appear as zero when I run your formula. Does that make sense?

Also, do you know a way that this formula could be modified to calculate the 2nd, 3rd, 4th and 5th "Rule" with the highest "Total"?

@gtsmith2 

To exclude empty rules:

 

=INDEX($E$2:$E$200, MATCH(1, ($E$2:$E$200<>"")*($A$2:$A$200=G2)*($D$2:$D$200=MAX(IF(($E$2:$E$200<>"")*($A$2:$A$200=G2), $D$2:$D$200))), 0))

 

again confirmed with Ctrl+Shift+Enter.

I'll have to think about your other question.

Thank you so much!
Regarding my second question I'm thinking that the AGGREGATE function might work but I have not had any luck with it.

@gtsmith2 

Assuming that the first formula is in row 2 (for example in H2):

 

=IFERROR(INDEX($E$2:$E$200, MATCH(1, ($E$2:$E$200<>"")*($A$2:$A$200=$G$2)*($D$2:$D$200=LARGE(IF(($E$2:$E$200<>"")*($A$2:$A$200=$G$2), $D$2:$D$200), ROW()-1)), 0)), "")

 

Fill down to row 6 (or however far you want).

 

@Hans Vogelaar

 

The formula posted at 1:05pm works perfectly. The last formula posted for some reason I cannot get to work. It does not error but when the function is entered/run nothing populates in the cell. Any suggestions? 

@gtsmith2 

See the attached sample workbook.

This works perfectly! Thank you again!

Based on having this setup I am thinking I would like to add some conditional logic on the "Category" and "Type" columns. Would that be a possible enhancement to the formulas provided in the sample workbook above? Thanks again!
best response confirmed by gtsmith2 (Occasional Contributor)
Solution

@gtsmith2 

See the new version.

Warning: it doesn't handle ties.

Thanks again! This works perfectly!
Hi Hans, so while I was finalizing my spreadsheet I noticed that the ties were a larger and more frequent problem than I first thought. Do you know of a way for the formulas that you created to handle ties. Basically some additional conditional logic that says if the "rule" is repeated then go to the next "rule" with the same total.

@gtsmith2 

See the attached version. I inserted a helper column that adds a very small disturbance to the Total amounts. You can hide this column if you wish.

Thank you for the help on this! This modification helps tremendously!