0

I am reasonably familiar with Excel formulas but I need to construct a more complex query and am not having much success at the moment.

I have simplified what I am trying to achieve for the purpose of the question.

Here is my source data:

enter image description here

What I am trying to do is construct a formula which will summarise the 'fed' status of each AnimalType. Here is a long hand version of what I am trying to do:

Using the range A1:A7, IF values in Column B = "Fed" WHERE AnimalType = "Cat" display 'All Animals Fed' ELSE display "All Animals Not Fed". Therefore, the output I would see for this table (using the conditional formatting rule) would be:

enter image description here

I hope this example provides enough detail for what I am trying to do. The actual solution I need is slightly more complicated than this but if I figure out how to to the above I am fairly confident I can figure out the rest.

0

2 Answers 2

2

Select B1:B2 cells in your "Recap" sheet, and type this formula:

=IF(ISERROR(MATCH($A$1:$A$2&"Not Fed", Animals!A$2:A$7&Animals!B$2:B$7, 0)), "All Animals Fed", "All Animals Not Fed")

This is an array formula, so you need to "validate" it using Ctrl+Shift+Enter.

In order to work, you need to replace "Cats" with "Cat" and "Dogs" with "Dog", or you can adapt the formula to delete last character.

6
  • Thanks for your response. I have tried this but get "All Animals Fed" in column B, and beneath that a zero. I can see the principle of what the formula is attempting to do though. Is there any way I could send you the file to take a look?
    – cw84
    Apr 24, 2014 at 13:50
  • Did you press Ctrl+Shift+Enter? Yes, please upload your file on a file hosting service.
    – ssssteffff
    Apr 24, 2014 at 14:04
  • I did. When I tried to fill down the formula I also got a circular reference error? Have now added the file here - thanks for your help with this. tbf.me/a/EF9B9
    – cw84
    Apr 24, 2014 at 15:45
  • My bad, there is an error in my formula. I forgot "Animals" sheet name for $B$2:$B$7 array, so it targets the wrong sheet (Sheet2). I've updated my answer, sorry again.
    – ssssteffff
    Apr 24, 2014 at 16:11
  • This is brilliant thank you! I did actually spot that sheet ref was missing earlier and add it myself, but then I think I must have forgotten to validate the function so assumed it wasn't working still. :) There is one slight modification to your answer - you mentioned highlighting B1:B2 and typing that function - if the same formula is applied to both rows I don't get the required result, so instead I have modified it slightly to ...(MATCH($A$1&"Not Fed"... in B1 and ...(MATCH($A$2&"Not Fed"... in B2. Thanks again!
    – cw84
    Apr 24, 2014 at 19:43
0

I would create a Pivot Table (Insert ribbon) from the range. I would drag the AnimalType field to the Row Labels zone, and the Fed? Field to the Column Labels zone. I would drag the AnimalType field to the Values zone.

This will give you a count of Animals by type and Fed status, with row and column totals. These can answer all the questions you are trying to answer, without coding any formulas, in a structure that can easily be extended to include other columns.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .