Average ifs with or in excel - excel

So, I have this problem, I would like to find the average of a column by using the OR function to check criteria from adjusted columns, I tried putting OR into AverageIf function, fail, also tried the "Average(IF(OR(" again not the correct return. Thought it is a simple thing could be done easily but don't know why it doesn't work. So my table is something like this:
ID: Rate Check 1 Check 2 Check 3
1 5 1 1 1
2 3 1 1
3 2 1
4 4
5 5 1 1
6 3
7 4 1
I would like to find the average of the rate column by checking if there are any value in either Check 1; Check 2 or Check 3 columns, so in the above case i will get the average of all but row with the id 4 and 6. Is this possible without using a helper column?

You can use SUMPRODUCT()
=SUMPRODUCT(((C2:C8<>"")+(D2:D8<>"")+(E2:E8<>"")>0)*(B2:B8<>"")*B2:B8)/SUMPRODUCT(--((C2:C8<>"")+(D2:D8<>"")+(E2:E8<>"")>0)*(B2:B8<>""))

If your first ID starts in A2, use this formula (edited to handle empty values in the "Rate" column):
=AVERAGE(IF(MMULT(LEN(C2:E8)*LEN(B2:B8),ROW(INDIRECT("1:"&COLUMNS($C$1:$E$1)))),B2:B8))

Related

Find all values in Column A which are present in Column B

Consider the sheet below:
A
B
1
4
3
5
2
2
5
0
4
1
I want to find if there is a match for each row of column 1 with any row of column 2. So ideally this would give me:
A
B
C
1
4
Yes
3
5
No
2
2
Yes
5
0
Yes
4
1
Yes
As a first and simple step, I am using =MATCH(A2,B2:B6) to get the index of the match and then manually calling this across the rows to get something like this:
A
B
C
1
4
6
3
5
-
2
2
3
5
0
2
4
1
1
I am now having a problem:
I want to apply this for a row of 500 in A and 2000 in B. I was thinking of manually filling in the first few rows and then select and drag over the first 500 rows. This however does not work as for each subsequent cell, it just changes the formula to =MATCH(A(N +1),B2 + N:B6 + N) which gives me wrong values and at worst, just repeats the older pattern ahead.
Can anyone help me with how I can just use the MATCH function to find all the values in A that are present in B?
Let me continue where you arrived:
=MATCH(A2,B2:B6,0)
(You forgot the last zero)
This formula is correct, but it is also wrong.
???
Well, when you drag it down, you get:
=MATCH(A3,B3:B7,0)
This is not what you want: you want the search term (A2) to change into A3 but you want the search array (B2:B6) not to change. In order to get this done, you need to work with absolute references. This looks like this:
=MATCH(A2,B$2:B$6,0)
When you drag this down, this is what you get:
=MATCH(A3,B$2:B$6,0)
=> ok so far.
Problem now: you need to translate your current results (a number or #N/A) into "yes" or "no". This can be done in numerous ways, let me give you an example:
=IF(ISERROR(MATCH(A2,B$2:B$6,0)),"No","Yes")
One remark: there exists an IFERROR() function in Excel, but this does not have an "else"-clause, hence the choice for the IF(ISERROR( combination.
Within Sheets you may try this out:
=index(if(len(A2:A),if(ifna(xmatch(A2:A,B2:B)),"Yes","No"),))
If you want to separate those matching values then could use FILTER() function.
=FILTER(A1:A5,COUNTIFS(B1:B9,A1:A5))
And for YES, NO dynamically, try MAP() function.
=MAP(A1:A5,LAMBDA(x,ISNUMBER(XMATCH(x,B:B))))

Excel using SUMIF to calculate totals of multiple columns

I'm trying to use Excle's SUMIF to calculate totals of Col1 to Col5 for dates that are similar.
My formula is as follows =SUMIF($A2:$A7,A10,$B2:$F7), but this only gives me the total of a single column.
How can I get the Totals of all the columns based on the date like I've shown in my results.
Date Col 1 Col 2 Col 3 Col 4 Col 5
1/5/2017 1 2 2
1/5/2017 5 3 1
1/5/2017 9 5 5
2/5/2017 10 5 3
2/5/2017 20 10 3
2/5/2017 6 8 1 5
Desired Results
1/5/2017 15 7 7 3 1
2/5/2017 30 11 11 11 8
use below formula in cell B11
=SUMIF($A$2:$A$7,$A11,B$2:B$7)
Per the example you provided, One solution is to use SUMPRODUCT
Multiplies corresponding components in the given arrays, and returns the sum of those products
Microsoft Docs give a thorough example, but per SO etiquette, here is an example in case of link-rot: [FYI, I used absolute reference for easier filling across, arbitrary how you get it done though]
Forumlas shown:
Formula is kind of hard to see without clicking on image:
=SUMPRODUCT(($B$3:$B$8=$B$11)*C3:C8)
This basically breaks down like this, it searches the B:B column for a match, and it will naturally return a true or false for the match, or 0/1 counterparts, and multiplys that by the number found in the column to the right (C3:C8), so it will either be 1 * # = # or 0 * # = 0

Compare multiple data from rows

I'm looking for a way to compare multiple rows with data to each other, trying to find the best possible match. Each number in every column must be an approximately match the other numbers in the same column.
Example:
Customer #1: 1 5 10 9 7 7 8 2 3
Customer #2: 10 5 9 3 5 7 4 3 2
Customer #3: 1 4 10 9 8 7 6 2 2
Customer #4: 9 5 6 7 2 1 10 5 6
In this example customer #1 and #3 is quite similar, and I need to find a way to highlight or sort the rows so I can easily find the best match.
I've tried using conditional formatting to highlight the numbers that are the similar, but that is quite confusing, because the amount of data is quite big.
Any ideas of how I could solve this?
Thanks!
The following formula entered in (say) L1 and pulled down gives the best match with the current row based on the sum of the absolute differences between corresponding cells:-
=MIN(IF(ROW($C$1:$K$4)<>ROW(),(MMULT(ABS($C1:$K1-$C$1:$K$4),TRANSPOSE(COLUMN($C$1:$K$4))^0))))
It is an array formula and must be entered with CtrlShiftEnter.
You can then sort on column L to bring the customers with lowest similarity scores to the top or use conditional formatting to highlight rows with a certain similarity value.
EDIT
If you wanted to penalise large differences in individual columns more heavily than small differences to try and avoid pairs of customers which are fairly similar except for having some columns very different, you could try something like the square of the differences:-
=MIN(IF(ROW($C$1:$K$4)<>ROW(),(MMULT(($C1:$K1-$C$1:$K$4)^2,TRANSPOSE(COLUMN($C$1:$K$4))^0))))
then the scores for your test data would come out as 7,127,7,127.
I'm assuming you want to compare customers 2-4 with customer 1 and that you are comparing only within each column. In this case, you could implement a 'scoring system' using multiple IFs. For example,:
A B C D E
1 Customer 1 1 1 2
2 Customer 2 1 2 2
3 Customer 3 0 1 0
you could use in E2
=if(B2=$B$1,1,0)+if(C2=$C$1,1,0)+if(D2=$D$1,1,0)
This will return a 'score' of 1 when you have a match and a 'score' of 0 when you don't. It then adds up the scores and your highest value will be your best match. Copying down would then give
A B C D E
1 Customer 1 1 1 2
2 Customer 2 1 2 2 2
3 Customer 3 0 1 0 1
so customer 2 is the best match.

how to count number between certain range of rows?

i would like to count number for every 7 rows, data are in one column. i use this formula, but it is not working.
from B8 to B14329, for every 7 rows, count number if it is equal to 3. so i know how many 3 in every 7 rows.
=COUNTIFS(B8:B14329, OFFSET($B$7,(ROW()-12)*7,0,7,1),B8:B14329,=3)
Thanks a lot!
i want something like this:
data count
3
2
3
1
3
3
1 4
1
2
2
3
3
1
1 2
.....
....
...
Simple and easy:
=SUMPRODUCT((B8:B14329=3)*(MOD(ROW(B8:B14329),7)=1))
Just change the =1 to your needs. To start with row 1 =1, 2 =2 ... 6 =6, 7 =0. This way, to start count at row 8 it is =1
EDIT: having your exaple now, you want something completely different... lol.
=IF(MOD(ROW(),7)=0,COUNTIF(A8:A14,3),"")
Put this in row 14 and then drag down... change the =0 as you need it.
Here's what I would do
Add a new column with the row index (8 to 14239) in your case
Add Yet another column, with a formula to tell whether the column you just added is a multiple of 7. Put it's value like "TRUE" or "FALSE"
You can use the MOD function to check the remainder of the division.
= MOD ( Number , Divisor )
By now, you should have, aside from the columns you already have, something like:
8-----FALSE
9-----FALSE
10-----FALSE
11-----FALSE
12-----FALSE
13-----FALSE
14-----TRUE
15-----FALSE
Once you have that, just apply a filter on the "TRUE/FALSE" column, select the "TRUE" values and you will be able to count the number of "3"s on the actual value column, by also using a filter on it.
I hope it helps, and it's easier than a really messy formula.

Excel 2013 complex countif formula

I have a source sheet set up like this:
Days Open Month
10 1
4 1
6 1
2 1
4 2
2 2
-1 2
4 3
6 3
7 4
3 4
etc
I'm trying to set up a formula to count rows based on the following criteria:
cells in Days Open column <=5 and <>-1 where the month is either 2, 3, or 4 (the worksheet will eventually have month numbers up to 12, and I need to group results quarterly). The total must then be divided by the total of ALL rows in which 2, 3, or 4 appears in the Month column.
I can't seem to get the first part of the COUNTIFS to work with both criteria... this is what I have so far that I'm trying to make work:
=COUNTIFS('Cumulative Complaints'!K:K,"<=5",'Cumulative Complaints'!K:K,"<>-1")/(COUNTIF('Cumulative Complaints'!L:L,"2")+COUNTIF('Cumulative Complaints'!L:L,"3")+COUNTIF('Cumulative Complaints'!L:L,"4"))
I've been looking around here and other excel forums and think maybe SUMPRODUCT is the way to go? I haven't been able to get that to work though, given the criteria needed on the Days Open column (<=5 and <>-1).
Try this SUMPRODUCT() FORMULA:
=SUMPRODUCT(('Cumulative Complaints'!K:K<=5)*('Cumulative Complaints'!K:K<>-1)*('Cumulative Complaints'!L:L>=2)*('Cumulative Complaints'!L:L<=4))/SUMPRODUCT(('Cumulative Complaints'!L:L>=2)*('Cumulative Complaints'!L:L<=4))
When using the SUMPRODUCT the condition AND is replaced with the *. It requires all four conditions to be True to return a 1; 1*1*1*1 = 1 if any are false they return 0 so 1*1*0*1 = 0. So as it iterates through the rows it returns a 1 or a 0 to the be added to the sum.
Wrapping a COUNTIF or COUNTIFS function in a SUM function allows you to use an array of constants as OR citeria.
=SUM(COUNTIFS('Cumulative Complaints'!K:K, "<>"&-1,'Cumulative Complaints'!K:K, "<="&5,'Cumulative Complaints'!L:L, {2,3,4}))/SUM(COUNTIF('Cumulative Complaints'!L:L, {2,3,4}))
This is not an array formula and does not require CSE.
My answer would be to take a different approach.
Excel has a very powerful feature called Pivot Tables, and I think it might be a good fit for your problem and other similar problems you may face.
First, I would add a couple columns to your table, like so:
Days Open Month Quarter RecentlyOpened
10 1 1 FALSE
4 1 1 TRUE
6 1 1 FALSE
2 1 1 TRUE
4 2 1 TRUE
2 2 1 TRUE
-1 2 1 FALSE
4 3 1 TRUE
6 3 1 FALSE
7 4 2 FALSE
3 4 2 TRUE
The formula for Quarter is: =CEILING(B2/3,1)
The formula for RecentlyOpened is: =AND(A2<>-1,A2<=5)
Second, select the table, and do Insert > Pivot Table.
Third, drag from the fields to the boxes, like so:
Drag Quarter to the ROWS box
Drag RecentlyOpened to the FILTERS box
Drag Month to the VALUES box
Fourth, click Sum of Month, and select Value Field Settings to change Sum to Count.
Fifth, set the RecentlyOpened filter to TRUE.
The result is this:
Pivot Tables often provide a solution that is more flexible and easier to read and understand versus complex formulas.

Resources