Dec 10 2019 03:39 AM
I have a table with names in column B and dates in row 1. The rest of the tables is the sales amount for the employee listed in column B on the date in row 1.
I want to find the max and the average for certain days. For example we have 12 sales on various days a quarter. I want to be able to find the max sales amount on days days that we had sales, and the days we didn't have sales as well as the averages sales amount on the days we had sales and the days we didn't have sales.
I can find the row that the data is in using match: =MATCH(A2,data!B:B,0) I can find the if is a sale using max and maxifs in an arrary: {=MAX(MAXIFS(data!$C2:$N2,data!$C$1:$N$1,report!$M$1:$P$1))} or using =AGGREGATE(14,4,MAXIFS(data!$C2:$N2,data!$C$1:$N$1,report!$M$1:$P$1),1)
There is a problem with finding the max if it is not a sale. I am not sure why. I tried: =AGGREGATE(14,4,MAXIFS(data!$C2:$N2,data!$C$1:$N$1,"<>"&report!$M$1:$P$1),1) & {=MAX(MAXIFS(data!$C2:$N2,data!$C$1:$N$1,"<>"&report!$M$1:$P$1))}
I can find the average if it is a sale if there is data for every day, but not if there is data missing. Then I get a #DIV/0 error.
Any ideas on this?
Dec 10 2019 05:12 AM
You may try this...
In C2
=MAX(MAXIFS(INDEX(data!$C$2:$N$13,MATCH($A2,data!$B$2:$B$13,0),),data!$C$1:$N$1,report!$M$1:$P$1))
In D2
=MAX(MAXIFS(INDEX(data!$C$2:$N$13,MATCH($A2,data!$B$2:$B$13,0),),data!$C$1:$N$1,"<>"&report!$M$1:$P$1))
Dec 10 2019 05:31 AM
As variant
Max If Sale
=AGGREGATE(14,6,1/--ISNUMBER(MATCH(data!$C$1:$N$1,$M$1:$P$1,0))*INDEX(data!$C$2:$N$13,MATCH($A2,data!$B$2:$B$13,0),0),1)
Max If Not Sale
=AGGREGATE(14,6,1/--NOT(ISNUMBER(MATCH(data!$C$1:$N$1,$M$1:$P$1,0)))*INDEX(data!$C$2:$N$13,MATCH($A2,data!$B$2:$B$13,0),0),1)
Average if sale
=SUMPRODUCT(ISNUMBER(MATCH(data!$C$1:$N$1,$M$1:$P$1,0))*INDEX(data!$C$2:$N$13,MATCH($A2,data!$B$2:$B$13,0),0))/SUMPRODUCT(ISNUMBER(MATCH(data!$C$1:$N$1,$M$1:$P$1,0))*(INDEX(data!$C$2:$N$13,MATCH($A2,data!$B$2:$B$13,0),0)<>0))
Average if Not Sale
=SUMPRODUCT(NOT(ISNUMBER(MATCH(data!$C$1:$N$1,$M$1:$P$1,0)))*INDEX(data!$C$2:$N$13,MATCH($A2,data!$B$2:$B$13,0),0))/SUMPRODUCT(--NOT(ISNUMBER(MATCH(data!$C$1:$N$1,$M$1:$P$1,0)))*(INDEX(data!$C$2:$N$13,MATCH($A2,data!$B$2:$B$13,0),0)<>0))
Dec 10 2019 10:49 AM
If your definition of best is "the shortest", I will recommend this formula in C2, as shown in the snapshot below:
Delving into the attached file, you'll see this formula in G2:
=SUMPRODUCT(COUNTIF($M$1:$P$1,data!$C$1:$N$1)*
INDEX(data!$C$2:$N$13,MATCH($A2,data!$B$2:$B$13,0),0))/
SUMPRODUCT(COUNTIF($M$1:$P$1,data!$C$1:$N$1*
(INDEX(data!$C$2:$N$13,MATCH($A2,data!$B$2:$B$13,0),0)<>"")))
Note that I used the elegant COUNTIF instead of the familiar ISNUMBER-MATCH combination.
Dec 11 2019 03:56 AM
The one for C2 worked perfectly, but the one for D2 did not. The "<>"& doesn't give an error but it doesn't seem to be working. You are doing it they way I wanted to do it. I wasn't sure how to do an index match with maxifs, but it is working. Why does the <> work with an array?
Anyone know the answer to this?
Dec 11 2019 04:18 AM
Your methods work. I ended up going:
=MAX(--ISNUMBER(MATCH(data!$C$1:$N$1,$M$1:$P$1,0))*INDEX(data!$C$2:$N$13,MATCH($A2,data!$B$2:$B$13,0),0),1)
=MAX(--NOT(ISNUMBER(MATCH(data!$C$1:$N$1,$M$1:$P$1,0)))*INDEX(data!$C$2:$N$13,MATCH($A2,data!$B$2:$B$13,0),0),1)
For the max of sales and not sales respectively.
What I do not understand is why if I try to do the same thing for average:
=AVERAGE(--ISNUMBER(MATCH(data!$C$1:$N$1,$M$1:$P$1,0))*INDEX(data!$C$2:$N$13,MATCH($A2,data!$B$2:$B$13,0),0),1)
It doesn't work. Why doesn't it?
Dec 11 2019 04:21 AM
This does work. It seems there should be a shorter way to do it. Is the issue dealing with Arrays or why doesn't the Average or averageif work here?
Dec 11 2019 04:30 AM
I don't know if you know this or not. Why does aggregate work with Large but not max, average or count. I know the difference between Large(,) and Max() bit it doesn't see like that should be applying here.
Dec 11 2019 04:44 AM
I guess with MAX() instead of AGGREGATE() you use array formula which is not needed in latest case.
AVERAGE() doesn't work since using ISNUMBER() you add to the array zeroes for the values where condition is not met (in addition to zero sales) and average with these zeroes. Plus ,1 at the end of the formula is not needed.
Dec 11 2019 04:51 AM
AGGREGATE() works with array formulas as references starting from function #14 (Large) and next one. Previous functions work with arrays themselves.
Dec 11 2019 04:57 AM
So I need an ifzero()function instead and isnumber(). What is the 1 at the end of the Max relating to? The --NOT?
Dec 11 2019 05:14 AM
I go an try this on my real data and I am getting an error with the Max for both. I get a #VALUE error. I copied a large subset over to test spreadsheet and I am getting the same results. I tried to trouble shoot this and I am not seeing it.
Do you (or anyone else) see what I am missing?
Dec 11 2019 05:16 AM
Extra 1 in this your formula
=AVERAGE(--ISNUMBER(MATCH(data!$C$1:$N$1,$M$1:$P$1,0))*INDEX(data!$C$2:$N$13,MATCH($A2,data!$B$2:$B$13,0),0),1)
IFZERO() doesn't exists and in any case doesn't help - you will remove from calculations days with zero sales.
MATCH() returns an array positions where one array with dates met another one, and errors (#N/A) otherwise. ISNUMBER() converts errors to zero and found positions to 1.
Dec 11 2019 10:54 AM
Dec 11 2019 08:13 PM
Two hopefully final questions.
1) Do I have an extra 1 on the max formulas?
=MAX(--ISNUMBER(MATCH(data!$C$1:$N$1,$M$1:$P$1,0))*INDEX(data!$C$2:$N$13,MATCH($A2,data!$B$2:$B$13,0),0),1)
=MAX(--NOT(ISNUMBER(MATCH(data!$C$1:$N$1,$M$1:$P$1,0)))*INDEX(data!$C$2:$N$13,MATCH($A2,data!$B$2:$B$13,0),0),1)
Or do I need that one for Max? I am confused on the difference as that was working with sample data.
2) I attached a the spreadsheet now with some of my real data. I am not getting a #Value Error. Do you see why?
Thank you for all of your help!!
Dec 11 2019 09:51 PM
That extra 1 was being considered as a number2 in the outer Max formula which I don't think is required.
The existing formula is producing the #Value! error because you cannot multiply a null string with a number. Wrap the internal calculation within IFERROR to handle that like below...
In B2
=MAX(IFERROR((--ISNUMBER(MATCH(data!$C$1:$CF$1,$H$1:$S$1,0)))*INDEX(data!$C$2:$CF$65,MATCH($A2,data!$B$2:$B$65,0),0),0))
In C2
=MAX(IFERROR((--NOT(ISNUMBER(MATCH(data!$C$1:$CF$1,$H$1:$S$1,0))))*INDEX(data!$C$2:$CF$65,MATCH($A2,data!$B$2:$B$65,0),0),0))
Both the formulas should be entered as Array Formulas.
Dec 11 2019 11:08 PM
Thank you!! That worked perfectly. I think I am having the same issue with the COUNTIF to find average, but I can't figure out where the IFERROR go. Any Advice?
Thanks again
Dec 12 2019 12:01 AM
Like this...
In D2
=SUMPRODUCT(IFERROR((COUNTIF($G$1:$S$1,data!$C$1:$CF$1)*
INDEX(data!$C$2:$CF$65,MATCH($A2,data!$B$2:$B$65,0),0))/
SUMPRODUCT(COUNTIF($G$1:$S$1,data!$C$1:$CF$1*
(INDEX(data!$C$2:$CF$65,MATCH($A2,data!$B$2:$B$65,0),0)<>""))),0))
In E2
=SUMPRODUCT(IFERROR((COUNTIF($G$1:$S$1,data!$C$1:$CF$1)*
INDEX(data!$C$2:$CF$65,MATCH($A2,data!$B$2:$B$65,0),0))/
SUMPRODUCT(COUNTIF($G$1:$S$1,data!$C$1:$CF$1*
(INDEX(data!$C$2:$CF$65,MATCH($A2,data!$B$2:$B$65,0),0)<>""))),0))
Dec 12 2019 06:10 AM
Solution
E2 had to be:
=SUMPRODUCT(IFERROR((COUNTIF($H$1:$S$1,data!$C$1:$CF$1)=0)*
INDEX(data!$C$2:$CF$65,MATCH($A2,data!$B$2:$B$65,0),0),0)/
SUMPRODUCT((COUNTIF($H$1:$S$1,data!$C$1:$CF$1)=0)*
(INDEX(data!$C$2:$CF$65,MATCH($A2,data!$B$2:$B$65,0),0)<>"")))
I got it to work!!! Thank you everyone for all of the help!!
Dec 13 2019 11:57 AM
Dec 12 2019 06:10 AM
Solution
E2 had to be:
=SUMPRODUCT(IFERROR((COUNTIF($H$1:$S$1,data!$C$1:$CF$1)=0)*
INDEX(data!$C$2:$CF$65,MATCH($A2,data!$B$2:$B$65,0),0),0)/
SUMPRODUCT((COUNTIF($H$1:$S$1,data!$C$1:$CF$1)=0)*
(INDEX(data!$C$2:$CF$65,MATCH($A2,data!$B$2:$B$65,0),0)<>"")))
I got it to work!!! Thank you everyone for all of the help!!