AVERAGEIFS returning #DIV/0 - excel-formula

So I am creating a database which compares demographics of patients among other things. I am trying to use the AVERAGEIFS function to find the mean operative time for specific surgeries for only patients who have a BMI of above 40.
=AVERAGEIFS(Data!P2:P255, Data!C2:C255, "*TYPE OF OPERATION*",Data!G2:G255, ",>40")
Column P contains the Operative time, C contains the type of operation and G contains the BMI of the patient. I keep getting a #DIV/0 error with this code. What am I doing wrong?

There should not be a comma in the last criteria ",>40". This should be ">40"
Also, if you fix the above and still get the same error, it is possible that none of the items in column C and/or G match your criteria.
See Microsoft Documentation on AVERAGEIFS

Related

ordering a list of names based upon related values, accounting for duplicate values, excel

I have a sheet that pulls metrics regarding employees from an internal source, I am trying to create an end of day report card and would like to display the names in ranking order based upon the metrics.
a small example for demonstration:
Columns A and B: An example of the kind of data in my sheet.
column D: I have used a variation of
=INDEX(A$2:A$6,MATCH(E2,B$2:B$6,0))
Column E:
=LARGE(B$2:B$6,1)
as you can see I am running into trouble with duplicate 'total' values creating an incorrect index number causing the first name that matches to be the result.
column G i have attempted to get around this by using:
=INDEX(A$16:A$20,MATCH(E19,B$16:B$20,0)+COUNTIF(B$16:B$20,E19)-1)
to attempt to account for the duplicates by adding a countif to the index number, of course, is an incorrect approach.
Not shown I also tried adding 0.5/'employee id number' to the total (0.5/an integer gives me a decimal between 0 and 0.5 allowing me to have each number be unique without causing any rounding problems to the displayed total. However, I think the decimal was ignored by the MATCH and it made no effect.
A weird problem has had me puzzled and I appreciate any help!
Have you tried something like this
=INDEX($A$2:$A$6,AGGREGATE(15,6,(ROW($A$2:$A$6)-ROW($A$2)+1)/($E2=$B$2:$B$6),COUNTIF($E$2:E2,E2)))
=INDEX($A$9:$A$13,AGGREGATE(15,6,(ROW($A$9:$A$13)-ROW($A$9)+1)/($E9=$B$9:$B$13),COUNTIF($E$9:E9,E9)))
=INDEX($A$16:$A$20,AGGREGATE(15,6,(ROW($A$16:$A$20)-ROW($A$16)+1)/($E16=$B$16:$B$20),COUNTIF($E$16:E16,E16)))

Why is my IF(AND) nesting generating incorrect results?

this may be a fairly simple one but I have spent a significant amount of time troubleshooting my formula and cannot identify as to why it is not returning the desired result.
I am working with two columns of data (A and B) which reference deals that my team is working on. Column A denotes the team member who is allocated to said transaction, and column B states whether or not the transaction is currently live ("TRUE" or "FALSE"). I am looking to return the email address for said team member if the transaction is live ("TRUE"). There are three team members contained within the spreadsheet, so I am nesting several AND functions.
I have tried the following code:
=
IF(AND(A1="TRUE",B1="Name1"),"name1.lastname1#x.com",
IF(AND(A1="TRUE",B1="Name2"),"name2.lastname2#x.com",
IF(AND(A1="TRUE",B1="Name3"),"name3.lastname3#x.com",0)))
The formula is returning "0" for each value, despite some of them meeting the relevant conditions.
Any help would be massively appreciated.
Thank you,
Looks like you just mixed up the columns.
Swap B1 and A1 expressions.

Understanding a lookup formula used to calculate balances based on transactions

Below I was given the following formula to lookup the last transaction in an account (there is a total of 4 accounts) and calculate its current balance based on the transaction of the current row (in this case row 1075). $E$2:$E1074 is the range for the varrying accounts. $F$2:$F1074 is the range of balances associated with each of those accounts. $C1075 is the current transaction we are looking at on row 1075. The error is included in the case that the account in column E does no match an other account in column E and therefore is a new account and the first transaction for that account. This code works.
=IFERROR(LOOKUP(2,1/($E$2:$E1074=$E1075),$F$2:$F1074)-$C1075,-$C1075)
I have experience with vlookup and hlookup but I don't understand the first two sections of this lookup function. specifically the 2 and the 1/($E$2:$E1074=$E1075). I'm not sure what these two values calculate and output to give the desired result. Thank you in advance for your help
Why 2 is for much the same reason as why a "big number" or "big text" (say zzz) can be useful in a MATCH function (that I tried to explain here). Here any number larger than 1 would serve since the objective is to look for what does not exist in order to make the search continue through to the last entry. Returning that last entry, rather than an error for "Not found" may not have been intended - but can be very useful.

index match with a max

*sample data I would expect it to show in regards to Axle 1 900 as this is the most recent date
Hi I am having issues with getting my formula to work.
I cant figure out how to get it to bring back the most recent date look up information.
Below is my current code
=INDEX('All Data'!$E$3:$E$6,MATCH(1,($H$5='All Data'!$D$3:$D$6)*($G$11='All Data'!$C$3:$C$6),0))
Thanks
Paula
If your dates are always increasing, then you can find the last value with this: {=INDEX('All Data'!$E$3:$E$6,MATCH(2,1/(($H$5='All Data'!$D$3:$D$6)*($G$11='All Data'!$C$3:$C$6))))}
Note the number 2, operation 1/... and no 0 as the last argument in MATCH. The trick is described here: find last match in column using built in functions in excel vba
UPDATE: If your dates are not increasing, then you need to do it in two steps. First, find the maximum date (let's name the cell MAX_DATE): {=MAX(($H$5='All Data'!$D$3:$D$6)*($G$11='All Data'!$C$3:$C$6)*($A$3:$A$6))} and then find the combination matching values in columns C and D and also the maximum date {=INDEX('All Data'!$E$3:$E$6,MATCH(1,($H$5='All Data'!$D$3:$D$6)*($G$11='All Data'!$C$3:$C$6)*(MAX_DATE='All Data'!$A$3:$A$6),0))}.

Rank the top 5 entries in different criteria

I have a table that I want to find the top X people in each of the different groups.
Unique Names Number Group
a 30 1
b 4 2
c 19 3
d 40 2
e 1 1
f 9 2
g 15 3
I've ranked the top 5 people by number by using =index($A$2:$A$8,match(large($B$2:$B$8,1),$B$2:$B$8,0)). The 1 in the LARGE function I linked to a ranked range so that when I dragged down it changed up the number.
What I would like to do next is rank the top x number of people in each group. So top 3 in group 1.
I tried =index($A$2:$A$8,match("1"&large($B$2:$B$8,1),$C$2:$C$8&$B$2:$B$8,0)) but it didn't seem to work.
Thanks
EDIT: After looking at the answers below I have realised why they are not working for me. My actual data that I want to use the formula with have multiple entries of numbers. I have adjusted the example data to show this. The problem I have is that if there are duplicate numbers then it returns both of the names even if one is not in the group.
Unique Names Number Group
a 30 1
b 30 2
c 19 3
d 40 2
e 1 1
f 30 2
g 15 3
Proof of Concept
Use the following formula in the example above in cell F2 and copy down and to the right as needed.
=IFERROR(INDEX($A$2:$A$8,MATCH(AGGREGATE(14,6,($C$2:$C$8=F$1)*($B$2:$B$8),ROW($A2)-1),$B$2:$B$8,0)),"")
In the header row provide the group numbers. or come up with a formula to augment and reset the group number as you copy down based on your X number in your question.
Explanation:
The AGGREGATE function unlike the large function is an array function without the need to use CSE. As such we can add criteria to what we want to use. In this case only 1 criteria was used and that was the group number. in the formula it was the following part:
($C$2:$C$8=F$1)
If there were multiple criteria we would use either an + operator as an OR or we would use an * operator as an AND.
The 6 option in the aggregate function allows us to ignore errors. This is useful when trying to get the small. It is also useful for dealing with other information that may cause errors that do not need to be worried about.
As this is technically an array operation avoid using full column/row references as they can bog down your system.
The basics of what the over all formula is doing is building a list that match the group number you are interested in. After filtering your numbers, it then determines which is the largest, second largest etc by what row you have copied down to. It then determine what row the nth largest number occurs in through the match function, and finally it returns to the corresponding name to that row with the index function.
Building on all the other great answers.
Because you have the possibilities of duplicate values in each group we need to do this with two formulas.
First we need to get the numbers in order. I used the Aggregate, but this could be done with the array LARGE(IF()) also:
=IFERROR(AGGREGATE(14,6,$B$2:$B$8/($C$2:$C$8=E$1),ROW(1:1)),"")
Then using that number and order we can reference, we can use a modified version of #ForwardEd's formula, using COUNTIF() to ensure we get the correct name in return.
=IFERROR(INDEX($A$2:$A$8,AGGREGATE(15,6,(ROW($B$2:$B$8)-ROW($B$2)+1)/(($C$2:$C$8=F$1)*($B$2:$B$8=E3)),COUNTIF(E$2:E2,E3)+1)),"")
This will count the number in the results returned and then bring in the correct name.
You could also solve this with array formulas - to filter a group whose name is stored in E1, your code
=INDEX($A$2:$A$8,MATCH(LARGE($B$2:$B$8,1),$B$2:$B$8,0))
would then be adapted to
=INDEX($A$2:$A$8,MATCH(LARGE(IF($C$2:$C$8<>E1,-1,$B$2:$B$8),1),$B$2:$B$8,0))
Note: After entering an array formula, you have press CTRL+SHIFT+ENTER.
Thank you to everyone who offered help but for some reason none of your methods worked for me, which I am sure was to do with the quality of my data. I used an alternate method in the end which is slightly convoluted but seemed to work.
=IF($C2="1",RANK($B2,$B$2:$B$8,1)+ROW()/10000,-1)
Essentially using the rank function and adding a fraction to separate out duplicate values.

Resources