Get number of unique values from a column with multiple criteria - excel

I am working on an Excel problem. Here is my questions:
name department year
a cs 5
b cs 8
c cs 2
d cs 3
a cs 1
b cs 10
a ma 7
f ma 8
h ma 2
The question is to get the number of unique name (only occur once) with department="cs" and year >2, in this case the result is 2 (i.e,"a" and "d" only occur once).
I knew the formula below might do the trick, but did not know how to put the range filtered by department="cs" and year >2 into the below formula.
=SUM(IF(COUNTIF(range, range)=1,1,0))

Use SUMPRODUCT:
=SUMPRODUCT((COUNTIFS(A:A,A2:INDEX(A:A,MATCH("zzz",A:A)),B:B,"cs",C:C,">2")=1)*(B2:INDEX(B:B,MATCH("zzz",A:A))="cs")*(C2:INDEX(C:C,MATCH("zzz",A:A))>2))

Related

Excel Swap Column of number

I am creating an excel file to swap excel columns which contains the number corresponding to the ASCII character such as low letter, upper letter, number, special characters.
Here is the original table and the corresponding letter to the number
A B C D E F G H
1 2 3 4 5 6 7 8
I want to swap each of the cell to the end. Meaning I need to swap 1 to 8. 2 to 7. 3 to 6.
A B C D E F G H
8 7 6 5 4 3 2 1
I would want to use the excel function to do this. Is there a way to achieve this? I have 156 columns.
what about this method.
A 1
B 2
C 3
D 4
E 5
F 6
G 7
H 8
If your data is always ordered then sorting would work.
But let's assume your data is not always alphabetically or numerically sortable, you can use a formula to reverse an unsorted list:
-
A
B
C
D
E
F
G
H
1
A
B
C
D
E
F
G
H
2
1
2
3
4
5
6
7
8
3
8
7
6
5
4
3
2
1
Rows 1 and 2 are your original data. Row 3 is the reversing formula.
Add the formula below into cell A3
=INDEX($A$2:$G$2, COLUMNS(A2:$G$2))
Note (important) that the first Range of the INDEX is absolute $A$2:$G$2, but the only the last value of the columns range is absolute A2:$G$2 (no dollars)
Either drag cell A3 across to H3 or copy cell A3 and paste over B3:H3
This has an advantage over plain sorting in that it can reverse unsorted lists for you.

List result of lookup A in B, B in C without helper column

I have 2 tables:
Table1 containing Customer & Part#
Table2 containing Part# & Type
(The actual data lists are larger)
Table1 (Customer & Part#) & Table3 (Helper):
Customer
Part#
Helper
A
1
X
B
2
Y
C
3
X
A
4
Y
A
5
X
A
5
X
A
2
Y
Table2:
Part#
Type
1
X
2
Y
3
X
4
Y
5
X
Desired result for combination of customer A and Type X:
Part#
1
5
5
These being the 3 results of part numbers in Table1 that are Customer A and the lookup of the Part# results in Type X (see also Helper column).
I'm able to retrieve the results by creating the helper column as shown in the example data, however I want to skip this column and solve it in one go. But I don't know if that's even possible.
I was thinking about something in this direction.. =INDEX (Table1[Part'#],IF(Table1[Customer]="A",ROW(Table1[Customer]))
..but there I get stuck. I think I can pickup from there with IF, ISNUMBER, SEARCH but my head errors there.
Does anybody know a way to skip the helper column for this?
PS I have office365, but FILTER is not yet released by company rules (unfortunately).
PS I prefer a formula solution, but VBA is allowed when necessary
Here is a formula solution for Excel version 2010 to 2019
In I3, formula copied down :
=IFERROR(INDEX(B:B,AGGREGATE(15,6,ROW(A$3:A$9)/(VLOOKUP(N(IF({1},B$3:B$9)),D$3:E$7,2,0)=H$3)/(A$3:A$10=G$3),ROW(A1))),"")

EXCEL Sum up points based on placements (combine VLOOKUP and SUM)

e.g. I have a list of race results:
A B C D E F...
NAME P. RACE1 RACE2 RACE
abc =? 1 3 3
bcd 3 2 4
cde 4 4 2
def 2 1 1
and another sheet with points for each result:
A B
PLACE POINT
1 10
2 5
3 2
4 1
Is it possible to get the total points in sheet1 column B based on the race results in column C-E..?
Is it a connection from VLOOKUP and SUM?
Yes, that's possible. You can use a SUMPRODUCT formula for that. You may use this one in column B:
=SUMPRODUCT((C2:E2=$A$13:$A$16)*$B$13:$B$16)
Your result will look like this:
This is an array function. The term C2:E2=$A$13:$A$16 will check for race 1 to 3 if it was 1st, 2nd, 3rd or 4th place. This will result in an "imaginary" array of TRUE and FALSE. For name "abc", it will look like that.
Those results are then multiplied with the points from B13:B16 and the sum is formed.
In Excel O365, one could use:
Formula in B2:
=SUM(VLOOKUP(C2:E2,H$2:I$5,2))

How do I create groups based on the sum of values?

I haven't been able to find anything like this and maybe I'm looking in the wrong place because I have very limited knowledge in programming so any help would be appreciated.
If there is a way to do this in Microsoft Excel without code that would be preferable, but if code is necessary then please help me by telling me the code is or how I can write it myself.
I need to be able to make separate groups of rows based on the sum of the values in a single column. This can be done either by inserting a "Total" row after a set summation value is reached or by color coding each group that reaches this summation value.
So, the order I see that this needs to happen is:
In one column, of a multi column table, sum the rows in order (if possible, starting on a row of my choosing)
Once the sum has reached a certain value, but doesn't exceed that value, those rows are grouped together
This occurs down the entire length of the table, creating separate groups based on the sum of the rows being as close to the set value as possible
For example:
Starting with this data:
Cust. │Qty.│ Type
A │2│ L
B │4│ XL
C │4│ M
D │9│ S
E │1│ L
F │9│ M
G │10│ L
H │1│ L
I │1│ XL
J │5│ L
K │1│ M
L │5│ S
M │4│ S
N │2│ S
The quantities are summed and checked against the value 10 and then grouped accordingly:
Cust. Qty. Type
A │2│ L
B │4│ XL
C │4│ M
│**Total: 10**│
D │9│ S
E │1│ L
│**Total: 10**│
F │9│ M
│**Total: 9**│
G │10│ L
│**Total: 10**│
H │1│ L
I │1│ XL
J │5│ L
K │1│ M
│**Total: 8**│
L │5│ S
M │4│ S
│**Total: 9**│
N │2│ S
... etc.
Or by color coding the different groups:
Color Coded Groups
The data table is constantly changing, with old rows being removed, and new ones added. The table is static once the information is pulled, so I would need to be able to apply this easily every time I pull updated data.
Also, if possible, the algorithm needs to be dynamic enough so if I insert, remove, or rearrange the rows that the groups are automatically updated.
Any help, suggestions, or comments would be greatly appreciated. Doing this manually is very time consuming and cumbersome due to the large amount of data that needs to be sorted.
Thank you in advance for the help.
One solution using only excel is this:
1) Add three additional columns to the table: "Total", "Starts Group", and "Group Number". So the table has 5 columns:
Customer Quantity Type Total Starts Group Group Number
2) Add one empty row between the headers and the data rows - this will make crafting and maintaining the formulas easier.
3) On the third row, which would be the first row with actual data (A | 2 | L), put the following formulas for the three new columns:
"Total" -> =IF(SUM(B3+D2)>10,B3,SUM(B3+D2))
"Starts Group" -> =IF(SUM(B3+D2)>10,TRUE,FALSE)
"Group Number" -> =IF(E3,F2+1,F2)
4) The "Group Number" column contains the information that you want. You can color code the rows using that value. Also, the table should be completely dynamic - you can add/remove rows as you wish and it will get recomputed.
So your specific example would look like this:
OrderID Contract Price BuySell OrderType Quantity
1 ZS 10914 Buy 6
2 ZS 10916 Buy 4
3 ZL 3188 Sell 9
4 ZM 3981 Sell 9
5 ZM 3985 Sell 2
6 ZS 10914 Buy 10
7 ZL 3186 Sell 9
8 ZM 3982 Sell 11
9 ZS 10910 Buy 2
10 ZS 10911 Buy 4
11 ZS 10913 Buy 2
12 ZS 10914 Buy 4
13 ZL 3184 Sell 9
14 ZM 3983 Sell 11
15 ZS 10926 Buy 10
16 ZL 3184 Sell 9
17 ZM 3983 Sell 11
18 ZS 10926 Buy 10
19 ZL 3184 Sell 9
20 ZM 3983 Sell 11

Analysing data using the column name

I have the following data.
Z Y Z Z
A1 A2 A3 A4 Total
1 2 5 10 16
2 3 5 11 18
3 4 6 12 21
4 4 7 12 23
I want to sum the rows using Just Zs ( the name of columns). I have a big data set, so I want to write a function to find out Zs in the whole sheet and the then sum them (Total).
Any Help would be appreciated
This can be done with SUMIF():
=SUMIF($1:$1,"Z",2:2)
NOTE
With the above formula it is using full row references so DO NOT put "Z" on top of the total column or it will throw circular errors.
If you want to have "Z" above it then you need to define the ranges:
=SUMIF(A$1:D$1,"Z",A2:D2)
How does this work:
=Sum(If(A$1:D$1="Z",$A$2:$D$100))
Assuming your headers are in row 1, columns A to D, and your data starts in row 2, and goes to row 100.

Resources