How do I count the number of cells in a column against criteria in another column - excel

I need help creating a formula to count number of unique delivery stops each day. The table below is similar to my actual data.
Name
Address
Sun
Mon
Tues
Wed
Bob
1 Main St
1
0
1
2
George
3 Main St
3
0
1
2
Tom
4 Main St
4
0
1
2
Harry
1 Main St
0
0
1
2
Randy
1 Main St
0
0
4
2
Homer
5 Main St
2
0
1
2
Bill
10 Main St
3
0
1
2
Jim
1 Main St
1
0
1
2
Joe
2 Main St
1
0
1
2
For instance, "1 Main St" is marked 4 times on the chart, but on Sunday there were 2 deliveries but only 1 actual stop at that location.
How would I go about calculating that based with a formula? I originally tried a ```=SUMPRODUCT```` but it wasn't calculating correctly, it would count each delivery stop, I'm not sure how to make it not count 0's and to combine multiple deliveries to the same address as a single delivery.
My last formula was "=SUMPRODUCT((COUNTIF($D$6:$D$96,$D$6:$D$96)=1)*$J$8:$J$98)
Where Column D is the addresses and J starts the delivery counts on Sunday.
Thanks
EDIT
Sorry, I wasn't clear with my question: I need a way to count the number of stops made per day (so if an address has multiple deliveries to different people, it's just counted as a single stop and 0's are skipped). Using Excel 2013

After many, many attempts, here it is...
Answer:
=SUM(IF(LEN(UNIQUE(FILTER(B2:B10;C2:C10>0;0);FALSE;FALSE))>1;1;0))
Where B2 is the first address, C2 is the first row under sunday.
This will give you unique delivery locations. So, if you visit the same place multiple times in one day, it is still counted as 1. If 0, it is counted as 0.
Your question was VERY unclear. Next time around, please tell us what you want the result to be.
This answer will give 6 for Sunday. If there are no deliveries, it will be zero. This last point took me hours to solve. COUNTIF won't work on single cells, only arrays. COUNT only works on numbers, COUNTA... Well, apparently COUNTA counts empty arrays (like if FILTER returns nothing). So I had to get the length (>1 for some reason). If it was greater than 1 in length, add 1, otherwise 0. And finally SUM it all.
Like I said, this is to calculate deliveries on Sunday, so this formula will be repeated for the other days.
Hope you like it! ^_^

Related

Count occurrences of strings just once per row in Google Sheets

I have strings of spreadsheet data that need counting by 'type' but not instance.
A B C D
1 Lin 1 2 1
2 Tom 1 4 2
3 Sue 3 1 4
The correct sum of students assigned to teacher 1 is 3, not 4. That teacher 1 meets Lin in lessons B and D is irrelevant to the count.
I borrowed a formula which works in Excel but not in Google Sheets where I and others need to keep and manipulate the data.
F5=SUMPRODUCT(SIGN(COUNTIF(OFFSET(B$2:D$2, ROW($2:$4)-1, 0), E5)))
A B C D E
2 Lin 1 2 1
3 Tom 1 4 2
4 Sue 3 1 4
5 1 [exact string being searched for, ie a teacher name]
I don't know what is not being understood by Google Sheets in that formula. Does anyone know the correct expression to use, or a more efficient way to get the accurate count I need, without duplicates within rows inflating the count?
So this is the mmult way, which works by finding the row totals of students assigned to teacher 1 etc., then seeing how many of the totals are greater than 0.
=ArrayFormula(sum(--(mmult(n(B2:D4=E5),transpose(column(B2:D4)))>0)))
or
=ArrayFormula(sum(sign(mmult(n(B2:D4=E5),transpose(column(B2:D4))))))
Also works in Excel if entered as an array formula without the ArrayFormula wrapper.
A specific Google Sheets one can be quite short
=ArrayFormula(COUNTUNIQUE((B2:D4=E5)*row(B2:D4)))-1
counting the unique rows containing a match.
Note - I am subtracting 1 in the last formula above because I am assuming there is at least one zero (non-match) which should be ignored. This would fail in the extreme case where all students in all classes are assigned to the same teacher so you have a matrix (e.g.) of all 1's. This would be more theoretically correct:
=ArrayFormula(COUNTUNIQUE(if(B2:D4=E5,row(B2:D4),"")))

FCR calculations in excel

I am trying to work the (First Contact Resolution) FCR in excel however so success.
Does anyone know an automated formula used in excel?
We have been trying to use formulas to check how many times a customer with the same customer ID calls us in 7 days.
Assuming your requirement
ID Date Calls Count in last 7 days from today
1 13-Mar-17 2
2 14-Mar-17 0
5 15-Mar-17 1
1 16-Mar-17 2
3 17-Mar-17 1
5 18-Mar-17 1
7 19-Mar-17 1
9 20-Mar-17 1
1 21-Mar-17 2
13 22-Mar-17 1
2 23-Mar-17 0
17 24-Mar-17 0
5 25-Mar-17 1
21 26-Mar-17 0
Putting ID in Column A and Dates in Column B and records starts from row 2
put this formula in Cell "C2":
=COUNTIFS(A:A,A2,B:B,">="&TODAY()-6,B:B,"<="&TODAY())
and drag it all way down to see the number of calls
or put this formula if you want to calculate last 7 days from the date in sheet:
=COUNTIFS(A:A,A2,B:B,">="&B2-6,B:B,"<="&B2)
Please let me know if you meant something else as I tried my best to assume the senario.

Finding the interval between demands in an excel forecasting sheet

I want to find a way for Excel to automatically give me the following 'interval':
Month 1 2 3 4 5 6
Demand 1 0 0 1 0 1
'Interval' 0 0 0 3 0 2
The 'interval' shows the amount of months between the demands. Is this doable in some sort of way? I couldnt find a function in Excel to do this. Maybe there is a way in VBA? I need this for the CROSTON forecasting method.
Thank you in advance for your time and effort!
J. Rommers
Count the number of consecutive zeros in the row above and adjust. In B3 enter:
=IF(B2=0,0,COUNTIF($B$2:B2,"=0")-SUM($A$3:A3))
and copy across:
Assuming the 3 columns are A, B and C use:
=MATCH(1,Bn:B1,0)-1
where Bn its the n of C

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.

Optimal to lookup and display column/row names from a table of binary data

Job Coach ConsumerName Monthly General Goals
Anna Joe 0 0 0
Sam John 0 0 0
Veron Jane 0 0 0
Bill Jack 1 1 1
Anna Jill 1 1 1
Jim 0 0 0
Bill Jiang 1 1 1
Jolly 0 1 1
Sam Jiant 0 0 0
Jap 0 1 1
Joule 1 1 1
Aardvark 0 1 0
Drake Darding 0 0 0
Hello, as you can see above I have two columns of strings; one column is "job coach" the other is "consumer name". There are three columns of 1's and 0's; monthly, general, and goals.
I'm trying to find the specific pattern of 1's and 0's in each of the rows, and to report it. For instance, the data says:
Consumer Jolly still has a a monthly which needs to be completed;
Consumer Aardvark still has a monthly which needs to be completed;
Consumer Aardvark still has a monthly and a goals which needs to be completed.
Lookup doesn't really work, because it only will return the first instance of the corresponding variable and not additionally instances.
I've tried a index function like this:
{=INDEX($C$2:$E$14,SMALL(IF($C$2:$C$14=0,ROW($C$2:$C$14)),ROW(1:1)),3)}
But that only would look up for a single column at a time, which makes the report rather cumbersome. I'm open to doing a loop in excel without formulas, however its not a simple looping formula, because I'm trying to look at each cell and to output the specific column name.
Any thoughts on how to best do it?
It's not exactly clear what the condition you want to check is, but if you want to check for a specific given pattern and return the customer name you can use this adjusted formula:
=INDEX($B$2:$B$14,SMALL(IF($C$2:$C$14&$D$2:$D$14&$E$2:$E$14="010",ROW($C$2:$C$14)-1),ROW(1:1)),1)
In your formula you checked only the first binary column and returned the last. You also had a mistake of returning the row number and not the index in the list which is row-1 in your case.
So notice:
The INDEX returns values from column B.
The IF checks a pattern of C&D&E equals a pattern like 010 which can be changed or set to a reference.
Then return the ROW()-1 in case your list starts at row 2, to return the index in the data and not the actual row.

Resources