Counting Criteria that Overlaps

Alan Donovan
Alan Donovan ✭✭
edited 07/01/20 in Formulas and Functions

I have a multi select dropdown column where users can select phases of a job they have experience in. For this example, let's say they have the options of "Pre-Execution", "Execution", and "Closeout". I want to total the number of users with "Execution" experience.


Using "=COUNTIF([dropdown]:[dropdown], CONTAINS("Execution", @cell))" includes both "Pre-Execution" and "Execution" in the user count, thus if the user only has "Pre-Execution" experience then they incorrectly get counted. Replacing CONTAINS with HAS then counts users with ONLY "Execution" experience, but if they also have other experience it excludes them completely. Same problem with using a NOT variation as I don't want to exclude those with both "Pre-Execution" and "Execution" experience. Any help on the correct formula to use?

Tags:

Best Answer

  • Alan Donovan
    Alan Donovan ✭✭
    Answer ✓

    After taking a mental break, here's the formula I eventually came up with to solve the issue:

    =COUNTIFS(dropdown:dropdown, CONTAINS("Pre-", @cell), dropdown:dropdown, SUM(LEN(@cell) - LEN(SUBSTITUTE(@cell, "Execution", ""))) / LEN("Execution") > 1) + COUNTIFS(dropdown:dropdown, CONTAINS("Execution", @cell), dropdown:dropdown, NOT(CONTAINS("Pre-", @cell)))

    Breaking this down, I use SUM(LEN(@cell) - LEN(SUBSTITUTE(@cell, "Execution", ""))) / LEN("Execution") to count how many times "Execution" exists in a cell. Using a COUNTIFS, I count the cell if it has both "Pre-" AND more than one instance of "Execution" (hence the ">1"). This covers the cases where "Pre-Execution" and "Execution" occur simultaneously. In instances where only "Execution" occurs without "Pre-Execution", the second COUNTIFS in the formula counts it by looking for "Execution" without an instance of "Pre-". Hope this helps future users!

Answers

Help Article Resources

Want to practice working with formulas directly in Smartsheet?

Check out the Formula Handbook template!