SOLVED

Adjusting a CountIF formula to survive a sort and filter

Copper Contributor

Hello!

 

I'm currently completing a business information systems unit and I've encountered an issue where the task requires me to use a CountIF formula drawing details from a Milk Products table (I7:Q18) and adjusting it with a ratio from the Milk production table (I28:N39). I would like the ability to be able to sort the Milk Products table, but my formula currently addresses fixed cell variables, and when I sort that table, the results understandably change.

 

The primary requirement for this particular column M31:38 requires the use of a CountIf formula, but I can't figure out what to pair with it to have it survive a re-sort of I7:Q18.

 

I've attached the spreadsheet for ease of reference.

 

Any help would be greatly appreciated!

 

TIA,

Paul

3 Replies
best response confirmed by PaulOlsen (Copper Contributor)
Solution

@PaulOlsen 

That could be

=COUNTIF($I$9:$I$16,I31)*
  INDEX($K$9:$K$16,MATCH($I31,$I$9:$I$16,0))*
  INDEX($L$9:$L$16,MATCH($I31,$I$9:$I$16,0))*
  INDEX($N$9:$N$16,MATCH($I31,$I$9:$I$16,0))*
  K31

@Sergei Baklan 

Wow. That's incredibly impressive and simpler than I was trying to make it. Thanks so much Sergei, I've been throwing my head at this for a week now trying to make it work! Am I right in reading this formula that its sorting the calculations for this by indexing against each of the columns which are filtered, matching it against the product code criteria in milk production, lining it up with the equivalent criteria in milk products, and then selecting the exact match based on that information?

 

Just want to make sure I understand how its working, instead of copying it and calling it a day.

 

Thanks SO much for your time, you've just cured a very big perpetual headache.

 

Kind Regards,

Paul

@PaulOlsen 

Paul, you are welcome.

Yes, MATCH finds the current row number for the product code in "Milk Products" table, and INDEX takes value from another column for the found row.

1 best response

Accepted Solutions
best response confirmed by PaulOlsen (Copper Contributor)
Solution

@PaulOlsen 

That could be

=COUNTIF($I$9:$I$16,I31)*
  INDEX($K$9:$K$16,MATCH($I31,$I$9:$I$16,0))*
  INDEX($L$9:$L$16,MATCH($I31,$I$9:$I$16,0))*
  INDEX($N$9:$N$16,MATCH($I31,$I$9:$I$16,0))*
  K31

View solution in original post