Excel - Count unique values on multiple criteria - excel-formula

My head is just sort of spinning on this and the solution examples. Can someone please provided a solution for this specific issue? Once I see it for what I need then it clicks on how to use elsewhere with different variables. Learning disorder of sorts. Thank you.
A B C D E
First Last Account Transaction Status
Frank Tomas 101 ACH Fraud
Dillon Krege 105 CC-DC
Joann Krimble 103 ACH
Frank Tomas 101 Wire
Clint Edwards 102 ACH Fraud
Joann Krimble 103 CC-DC Fraud
Joann Krimble 103 ACH
Unique Account (column C) using Transaction (column D) of "ACH" and coded as Status (column E) of "Fraud"?
There are 3000+ rows in this sheet, if that makes a difference. Pivot table not an option, which I could have done quickly.

use:
=SUMPRODUCT(((D2:D8="ACH")*(E2:E8="FRAUD"))/(COUNTIFS(C:C,C2:C8,D:D,"ACH",E:E,"FRAUD")+(D2:D8<>"ACH")+(E2:E8<>"FRAUD")))

This is essentially the same method as the response from Scott Craner but incorporates dynamic column length.
=SUMPRODUCT(((D$2:INDEX(D:D, MATCH(1E+99, C:C))=H2)*(E$2:INDEX(E:E, MATCH(1E+99, C:C))=I2))/
(COUNTIFS(C$2:INDEX(C:C, MATCH(1E+99, C:C)), C$2:INDEX(C:C, MATCH(1E+99, C:C)),
D$2:INDEX(D:D, MATCH(1E+99, C:C)), H2, E$2:INDEX(E:E, MATCH(1E+99, C:C)), I2)+
(D$2:INDEX(D:D, MATCH(1E+99, C:C))<>H2)+(E$2:INDEX(E:E, MATCH(1E+99, C:C))<>I2)))
This formula's dynamic column length does depend on the accounts being true numbers.

Related

How to filter String data using search list in Google sheets/Excel?

I want to filter addresses (column A) if they contain any city name from city list (column B). Here is how data looks like:
Adresses (Col A)
Cities (Col B)
900 Rancho Diego Pkwy, Buellton, CA 92028
Ventura
3850, Toepperwein Rd, Antonio, TX 78264
San Antonio
3250 El Camino Real, Atascadero, CA 93444
Buellton
2340 Palma Dr, Ventura, CA 93090
New York
Valley Rd, Santa Maria, CA 93420
In the above table, only 2 cities (Ventura, Buellton) in column B are found in Addresses in Column A, so the output should be:
900 Rancho Diego Pkwy, Buellton, CA 92019
2340 Palma Dr, Ventura, CA 93003
I tried following formulas but to no effect:
=FILTER(A2:A, REGEXMATCH(A2:A, B2:B))
=FILTER(A2:A, MATCH(A2:A, B2:B,0))
=FILTER(A2:A, COUNTIF(B2:B, A2:A))
How to compile list of addresses (Col A) if any city name (Col B) is found in the address? Any help would be much appreciated.
withing GSheets please try:
UPDATED FORMULA:
this strictly extracts the cities names within the address to tally against the list in Column B to avoid random mismatches.
=FILTER(A2:A,REGEXMATCH(BYROW(A2:A,LAMBDA(ax,IF(ax="",,IFNA(IFNA(REGEXEXTRACT(ax,", ([^,]*), [A-Z]{2}"),REGEXEXTRACT(ax,", ([^,]*), [^,]*$")))))),"(?i)"&TEXTJOIN("|",1,B2:B)))
Use FILTER() with MMULT() in Excel
• Formula used in cell E3
=FILTER(B3:B7,MMULT(N(ISNUMBER(SEARCH(TRANSPOSE(C3:C6),B3:B7))),ROW(C3:C6)^0))
Works in Google-Sheets as well:
• Formula used in cell E3
=FILTER(B3:B7, MMULT(N(ISNUMBER(SEARCH(TRANSPOSE(C3:C6),B3:B7))),SEQUENCE(ROWS(C3:C6),1,1,0)))
An alternative approach using BYROW()
• Formula used in cell E3
=FILTER(B3:B7,BYROW(N(ISNUMBER(SEARCH(TOROW(C3:C6),B3:B7))),LAMBDA(m,SUM(m))))
For Google-Sheets replace the TOROW() with TRANSPOSE()
• Formula used in cell E3
=FILTER(B3:B7,BYROW(N(ISNUMBER(SEARCH(TRANSPOSE(C3:C6),B3:B7))),LAMBDA(m,SUM(m))))
Instead of taking all the rows it is better to use Table Structured References
• Formula used in cell E3
=LET(_cityName,FILTER(C3:C1048576,C3:C1048576<>""),
_addresses,FILTER(B3:B1048576,B3:B1048576<>""),
FILTER(_addresses,MMULT(N(ISNUMBER(SEARCH(TRANSPOSE(_cityName),_addresses))),SEQUENCE(ROWS(_cityName)))))
With BYROW()
• Formula used in cell E3
=LET(_cityName,FILTER(C3:C1048576,C3:C1048576<>""),
_addresses,FILTER(B3:B1048576,B3:B1048576<>""),
_searchArray,N(ISNUMBER(SEARCH(TOROW(_cityName),_addresses))),
FILTER(_addresses,BYROW(_searchArray,LAMBDA(m,SUM(m)))))
Or, create a Defined Name in Name Manager with the LAMBDA() formula and use the range as per your need.
Refers To:
=LAMBDA(Cities,Addresses,
LET(_cityName,FILTER(Cities,Cities<>""),
_addresses,FILTER(Addresses,Addresses<>""),
_searchArray,N(ISNUMBER(SEARCH(TOROW(_cityName),_addresses))),
FILTER(_addresses,BYROW(_searchArray,LAMBDA(m,SUM(m))))))(C3:C1048576,B3:B1048576)
• Formula used in cell E3
=LISTDATA(C3:C1048576,B3:B1048576)
In Google-Sheets
=FILTER(B3:B,BYROW(N(ISNUMBER(SEARCH(TRANSPOSE(FILTER(C3:C,C3:C<>"")),B3:B))),LAMBDA(m,SUM(m))))
You were close with this
=FILTER(A2:A, REGEXMATCH(A2:A, B2:B))
The second argument of REGEXMATCH shouldn't be a range though, this will work:
=FILTER(A2:A,REGEXMATCH(A2:A,TEXTJOIN("|",1,B2:B)))

Excel vlookup on two dimensions AND multiple column criteria

I am looking for a formula to reference a value from a table based on two column values and one row value. I tried for hours with different sumifs, match, etc. formulas but nothing worked. An example would look as follows:
Manager Marketplace Jan Feb Mar
mgr1 US 312 546 987
mgr1 DE 546 329 715
mgr2 FR 267 195 546
The formula should find the correct value if given for example mgr1, US and Feb.
Any Ideas?
Best,
Moritz
Another option:
=INDEX(C2:E4,MATCH(1,INDEX((A2:A4="mgr1")*(B2:B4="US"),0,1),0),MATCH("Feb",C1:E1,0))
=INDEX(A:E,MATCH("mgr1"&"US",A:A&B:B,0),MATCH("Feb",1:1,0))
This is an example of a two way lookup, concatenating the vertical lookup section of the index formula.
Try,
=INDEX(C:E, AGGREGATE(15, 7, ROW($2:$9)/((A$2:A$9=H2)*(B$2:B$9=I2)), 1), MATCH(J2, C$1:E$1, 0))

Split list into two lists depending on adjacent cell value

I need a little help, I have an Excel book with a long list of customers and in the adjacent cell is ether a 1 or 0 depending if the customer has ordered in the past month.
How can I split this list into 2 lists on another page one been ordered in the past month and the other not ordered,
Im unable to use Macros due to security levels on the PC.
Thanks
Try,
'for ones
=INDEX(A:A, AGGREGATE(15, 7, ROW(B$2:INDEX(B:B, MATCH(1E+99, B:B)))/(B$2:INDEX(B:B, MATCH(1E+99, B:B))=1), ROW(1:1)))
'for zeroes
=INDEX(A:A, AGGREGATE(15, 7, ROW(B$2:INDEX(B:B, MATCH(1E+99, B:B)))/(B$2:INDEX(B:B, MATCH(1E+99, B:B))=0), ROW(1:1)))
Of course, you will have to modify to suit the different worksheet.
See the image below. Using array formulas (Ctrl+Shift+Enter) I entered this into D2:D8:
=IFERROR(INDEX(A2:A8,SMALL(IF(B2:B8,ROW(A2:A8)-ROW(A1)),ROW(A2:A8)-ROW(A1))),"")
and this into E2:E8:
=IFERROR(INDEX(A2:A8,SMALL(IF(1-B2:B8,ROW(A2:A8)-ROW(A1)),ROW(A2:A8)-ROW(A1))),"")
Explanation
This is how Excel will calculate the first formula:
=IFERROR(INDEX(A2:A8,SMALL(IF(B2:B8,ROW(A2:A8)-ROW(A1)),ROW(A2:A8)-ROW(A1))),"")
=IFERROR(INDEX(A2:A8,SMALL(IF({1;0;1;0;0;0;1},{2;3;4;5;6;7;8}-1),{2;3;4;5;6;7;8}-1)),"")
=IFERROR(INDEX(A2:A8,SMALL(IF({1;0;1;0;0;0;1},{1;2;3;4;5;6;7}),{1;2;3;4;5;6;7})),"")
=IFERROR(INDEX(A2:A8,SMALL({1;FALSE;3;FALSE;FALSE;FALSE;7},{1;2;3;4;5;6;7})),"")
Since the second argument of SMALL is an array, it will find the 1st, 2nd, 3rd, etc. value, ignoring FALSE (it will return #NUM! for the 4th through 7th value).
=IFERROR(INDEX(A2:A8,{1;3;7;#NUM!;#NUM!;#NUM!;#NUM!}),"")
=IFERROR({"A";"C";"G";#NUM!;#NUM!;#NUM!;#NUM!},"")
={"A";"C";"G";"";"";"";""}

Excel 2013 - Sum with a date range

Good day, I have finally decided to ask for help. I have 1 workbook, multiple worksheets. The formula gives me #Value! which I am understanding that it has a wrong datatype. I am simply wanting look at a range within 1 column of dates, then add a column of numbers in 2 separate columns and divide those 2 columns and multiply by 30. It amounts to this. SUM(D31/C31)*30. This small formula works great when just using the numbers. I am taking total hours divided by amount of production multiplied by 30 dollars per hour. Obviously I will do this for each month of the year.
The 2 sheets are labeled as follows. This formula below resides on sheet "Monthly". It is referencing sheet "Overall Cost". I am hoping I have given you enough information that perhaps you might have the time to assist me. Note: I have the range pretty long because this is supposed to work for the whole year so I made it 10,000 rows deep.
Formula:
=SUMPRODUCT(('Overall Cost'!$B$3:$B$10000<=DATE(2015,9,30))*('Overall Cost'!$B$3:$B$10000>=DATE(2015,9,1)),SUM(('Overall Cost'!$D$3:$D$10000)/SUM('Overall Cost'!$C$3:$C$10000))*30)
Sample data:
"B" "C" "D"
SQ FT Hours
Date OH OH
Wednesday 8/10/15 3427 232
Thursday 8/11/15 5536 232
Friday 8/12/15 2364 232
Monday 8/1/15 6408 232
Tuesday 9/4/15 2499 232
Wednesday 9/5/15 870 232
You cannot use a SUM function within a SUMPRODUCT function like that. The SUMPRODUCT is trying to process each row by row and the SUM is totalling all of the rows into a single figure.
You are also going to get a number of #DIV/0! errors due to SUMPRODUCT's strong calculation mode. Your extra rows ranging down to 10000 can be truncated to the extent of the dates in column B. Since they are the criteria, it stands to reason that no numbers in column C and D would be significant in rows beyond the last date.
=SUMPRODUCT(('Overall Cost'!B$3:INDEX('Overall Cost'!B:B, MATCH(1E+99, 'Overall Cost'!B:B ))<DATE(2015, 10, 1))*
('Overall Cost'!B$3:INDEX('Overall Cost'!B:B, MATCH(1E+99, 'Overall Cost'!B:B ))>=DATE(2015, 9, 1)),
'Overall Cost'!$D$3:INDEX('Overall Cost'!D:D, MATCH(1E+99,'Overall Cost'!B:B)),
30/'Overall Cost'!$C$3:INDEX('Overall Cost'!C:C, MATCH(1E+99,'Overall Cost'!B:B )))
I've also adjust your maths hierarchy a bit. Multiplying the division of columns C and D was the same as multiplying column D by the fraction created by 30 over column C.
      
Providing you have no zero values in column C you should be alright. If you do then an IFERROR function or additional criteria may have to be brought in. This formula also limits calculation only to exactly what is needed with no blank 'safety-zone' of blank cells.
If yo are still receiving #DIV/0! errors then there must be blank cells or cells with 0 in column C. A #DIV/0! error is literally that; you are trying to divide a number by zero.
This can be solved with the IFERROR function but an extra layer of processing is required so you need to use Ctrl+Shift+Enter↵ to finalize the following formula.
=SUMPRODUCT((oc!B$3:INDEX(oc!B:B, MATCH(1E+99, oc!B:B ))<DATE(2015, 10, 1))*
(oc!B$3:INDEX(oc!B:B, MATCH(1E+99, oc!B:B ))>=DATE(2015, 9, 1)),
oc!$D$3:INDEX(oc!D:D, MATCH(1E+99,oc!B:B)),
IFERROR(30/oc!$C$3:INDEX(oc!C:C, MATCH(1E+99,oc!B:B )), 0))
This can be mimicked with a non-CSE formula by forcing the numerator to zero and the denominator to one when encountering a #DIV/0! situation.
=SUMPRODUCT((oc!B$3:INDEX(oc!B:B, MATCH(1E+99, oc!B:B ))<DATE(2015, 10, 1))*
(oc!B$3:INDEX(oc!B:B, MATCH(1E+99, oc!B:B ))>=DATE(2015, 9, 1))*
(oc!$C$3:INDEX(oc!C:C, MATCH(1E+99,oc!B:B ))<>0),
oc!$D$3:INDEX(oc!D:D, MATCH(1E+99,oc!B:B)),
30/(oc!$C$3:INDEX(oc!C:C, MATCH(1E+99,oc!B:B ))+
(oc!$C$3:INDEX(oc!C:C, MATCH(1E+99,oc!B:B ))=0)))

INDEX/MATCH with multiple criteria

Need assistance with an Excel formula.
I am trying to get a summary of a range. I have been playing with the Match, Index, Countif functions and can create a list of unique dates and then using a vlookup to return the persons name.
I need something to take the persons name into account so if the same date appears for 2 people, it shows as 2 different lines in the output.
Please see table below - A&B is the input, D&E is what I can currently get, G&H is the output I want.
Thanks in advance.
A B C D E F G H
1 13/01/15 RYAN 13/01/15 RYAN 13/01/15 RYAN
2 13/01/15 RYAN 14/01/15 RYAN 14/01/15 RYAN
3 14/01/15 RYAN 15/01/15 RYAN 14/01/15 FRANK
4 14/01/15 RYAN 15/01/15 RYAN
5 14/01/15 RYAN
6 14/01/15 RYAN
7 14/01/15 FRANK
8 14/01/15 FRANK
9 14/01/15 FRANK
10 15/01/15 RYAN
11 15/01/15 RYAN
All knowledge I have of Excel in self taught thanks the forums like stackoverflow so any help is greatly appreciated.
Much the easiest way to achieve this is with a PivotTable. Add labels to Columns A and B (say Date and Name) then select A:B, INSERT, Tables - PivotTable, chose where in Existing Sheet or New Sheet and drag Date and then Name (below) into ROWS.
Reformat as desired.
The style of array formula I prefer requires that there be an unused cell directly above the first formula to avoid circular references. This unused cell can be used as a column header label.
The array formulas¹ used in D2:E2 are,
=IFERROR(INDEX(A:A, MATCH(0, COUNTIFS(D$1:D1,A$1:INDEX(A:A, MATCH(1E+99, A:A))&"",
E$1:E1,B$1:INDEX(B:B, MATCH(1E+99, A:A))&""), 0)), "")
=IFERROR(INDEX(B:B, MATCH(0, COUNTIFS(D$1:D1,A$1:INDEX(A:A, MATCH(1E+99, A:A))&"",
E$1:E1,B$1:INDEX(B:B, MATCH(1E+99, A:A))&""), 0)), "")
Fill down as necessary. These array formulas have their most active lookup ranges dynamically truncated at the row containing the last date in column A to cut calculation cycles down to the minimum necessary.
    
I have added an extra entry for Frank at the bottom of the list of your sample data to further demonstrate the double unique lookup.
¹ Array formulas need to be finalized with Ctrl+Shift+Enter↵. If entered correctly, Excel with wrap the formula in braces (e.g. { and }). You do not type the braces in yourself. Once entered into the first cell correctly, they can be filled or copied down or right just like any other formula. Try and reduce your full-column references to ranges more closely representing the extents of your actual data. Array formulas chew up calculation cycles logarithmically so it is good practise to narrow the referenced ranges to a minimum. See Guidelines and examples of array formulas for more information.
With helper columns this could be achieved without any array formulas. The idea is to get first a concatenation of date and name, then get only the line number of the first occurrence of date&name in the list, get those line numbers without duplicates and finally get the INDEXes of those line numbers from A:A and B:B.
Formulas:
D1:D13 =A1&B1
E1:E13 =IF($D1<>"",MATCH($D1,$D:$D,0),"empty")
F1 =MIN($E:$E)
F2:F13 =LARGE($E:$E,COUNTIF($E:$E,">"&$F1))
H1:H13 =INDEX($A:$A,$F1)
I1:I13 =INDEX($B:$B,$F1)

Resources