How to get distinct count in excel from two columns - excel

Let's say I have two columns as below:
Now if I want to get distinct count based on my multiple criteria, I tried to apply the formula below
=SUM(COUNTIFS(A2:A7,"Arnold",B2:B7,"1"))
Now the result is 2 because Arnold matches twice with Column B with value 1.
Now I need the output to be 1 based on distinct value in column B.

USE
=SUMPRODUCT((B2:B7=1)/(COUNTIFS(A2:A7,A2:A7,B2:B7,1)+(B2:B7<>1)))

Related

Single formula with Multiple Countifs and where data table contains duplicate values in more than one column

The excel file contains a structure table. (which I find difficult to work with but I can't alter the file structure, I am just adding a summary tab with various counts from the data table.)
Item
Month
1
2
2
2
2
2
2
3
3
3
3
4
The item number itself can repeat and be repeated within the same month.
I was able to get a count of total number of unique items using this formula.
=SUMPRODUCT((Item_tab[Item]<>"")/COUNTIF(Item_tab[Item],Item_tab[Item]&""))
Looking for how to count the number of unique items within a specific month.?
Example of Desired output.
Edit/Set formula for Month 2 , output should be 2
Edit/Set formula for Month 3 , output should be 2
Edit/Set formula for Month 4 , output should be 1
I cannot figure out how to apply countifs to something that needs to avoid duplicates in multiple columns.
Tried this but returns #VALUE!
=SUMPRODUCT((Item_tab[Item]<>"")/COUNTIFS(Item_tab[Item],Item_tab[Item]&"",'Item'!M:M,6))
The month column was added later and I don't know how why or how to get that column to have the structured table column Header like everything else.
The sheet name is Item
The Table Name is Item_tab
I can find where to rename the table but not the columns. Not sure the variance is causing an issue. The month column is absolutely part of the table in every way that I can see.
You can try the following in cell D2:
=LET(A, A2:A7, B, B2:B7, uxB, UNIQUE(B), cnts, BYROW(uxB, LAMBDA(u,
ROWS(UNIQUE(FILTER(A, B=u))))), HSTACK(uxB, cnts))
Here is the output:
If you want to get the result repeated instead of consolidating the result by unique months, you can try the following:
=LET(A, A2:A7, B, B2:B7, uxB, UNIQUE(B), BYROW(B, LAMBDA(u,
ROWS(UNIQUE(FILTER(A, B=u))))))
If you don't have such function available, you can try the following formula in D2, it produces the same result as the first formula:
=CHOOSE({1,2}, UNIQUE(B2:B7),
MMULT(N(MMULT(TRANSPOSE(N(B2:B7=TRANSPOSE(UNIQUE(B2:B7)))),
N(A2:A7=TRANSPOSE(UNIQUE(A2:A7))))>0), SEQUENCE(ROWS(UNIQUE(A2:A7)),,1,0)))
or using LET for a better reading and maintenance:
=LET(A, A2:A7, B, B2:B7, CHOOSE({1,2}, UNIQUE(B),
MMULT(N(MMULT(TRANSPOSE(N(B=TRANSPOSE(UNIQUE(B)))),
N(A=TRANSPOSE(UNIQUE(A))))>0), SEQUENCE(ROWS(UNIQUE(A)),,1,0))))

Number occurrences in another cell (Excell) [duplicate]

I have simple problem, but I've not be able to get an answer from searching. I require a column to calculate the number of the nth occurrence of a value. It's best explained in this picture
I require a method to calculate column B.
I'd be very grateful for any help.
Are you looking to merely provide a count of the distinct entries of column A in column B? Or merely add a formula to come up with the table in your link?
If the latter, then the formula to write in cell B2 is:
=COUNTIF(A$2:A2,A2)
then copy/paste it down column B. Note - if your data is both a Date and Time, but the cell is formatted to only display a date, you may not get the results you want. You'd need to interject a new column with a "floor" calculation to round the date/time value to a date (Excel date times are decimal, with integer part dictating the date, and remaining 0.0 -> 1.0 dictating the time of day)
If you just want to derive a table of the counts of distinct entries in column A, then a pivot table will do this for you - simple add a pivot table to cover the data in column A, then select column A into the rows category, and then also drag it into the values category, ensuring the field is set to "Count of". You should then have a table with the distinct entries in your data set in one column, and the count of their occurrences in the other column.
You can use the COUNTIF worksheet function, with a relative address.
Eg. In cell B2, enter this formula:
=COUNTIF(A$2:A2,A2)
And then fill-down.
Use the following formula to generate the required series:
=COUNTIF($A$1:A1,A1) and strech(copy) it in all the cells
This will generate result like this:
A 1 COUNTIF($A$1:A1,A1)
A 2 COUNTIF($A$1:A2,A2)
C 1 COUNTIF($A$1:A3,A3)
C 2 COUNTIF($A$1:A4,A4)
B 1 COUNTIF($A$1:A5,A5)
B 2 COUNTIF($A$1:A6,A6)
A 3 COUNTIF($A$1:A7,A7)
C 3 COUNTIF($A$1:A8,A8)
D 1 COUNTIF($A$1:A9,A9)
D 2 COUNTIF($A$1:A10,A10)
D 3 COUNTIF($A$1:A11,A11)
D 4 COUNTIF($A$1:A12,A12)

Get Spill-result to reference correct row #

As a result of this closed topic I started wondering myself the following:
Let's say we have data like this:
A
1
a
2
b
3
c
4
a
5
b
6
c
7
g
8
h
9
i
I want to divide the list into 3 (I used TEXTJOIN) and check which of the 3 of these is unique.
I used a combination of MATCH and COUNTIF (and SEQUENCE) for this.
Question:
I managed to get that correct, but wanted to get the 3 textjoin-results all at once as a spill range.
In the picture below you can see my results of attempts, but I couldn't get the TEXTJOIN to reference the correct column in it's spill-result. What is missing, or what am I doing wrong?
Not sure what you want for output.
If all you want is to determine which is/are unique entries, just use the UNIQUE function. Note the exactly_once argument.
For example:
C1: =OR(B1=UNIQUE($B$1:$B$3,,TRUE))
and fill down, but the formula will fill down automatically.
Edit:
I don't know how to get the TEXTJOIN function to spill down in groups of three like you want. However, to be able to enter the formula just once, and have the results appear in column B, and have that adjust as you add/remove entries from column A, you can use a Table structure.
In that case, row 1 would be the column headers, and the formula in B2 would be:
=IFERROR(TEXTJOIN(",",TRUE,INDEX([Column1],SEQUENCE(3)+(ROW()-ROW(Table2[#Headers]))*3-3)),"")`
No need to fill down.
Edit2:
To create a list of unique (listed only once) values from Column B in Column C, you can use the UNIQUE function. However, due to limitations on SPILL functions within a Table, this column cannot be part of the table.
In the example below, where Column C is NOT part of the table:
B2: =IFERROR(TEXTJOIN(",",TRUE,INDEX([Column1],SEQUENCE(3)+(ROW()-ROW(Table2[#Headers]))*3-3)),"")
C2: =UNIQUE(Table2[Column2],,TRUE)
Edit3:
If you were OK with omitting columnB, and reporting the unique triplets in separate cells instead of concatenated, you could do that with the UNIQUE function:
or, without a table,
=UNIQUE(INDEX($A:$A,SEQUENCE(COUNTA($A:$A)/3,3,2)),,TRUE)
Note that the start argument in the SEQUENCE function represents the first line of data in column A, (2 in this example)

How to skip counting same value set in 2 columns that appears in another 2 columns set

Good day, I need some help on how to form an Excel formula to count distinct for values in 2 columns with other columns:
I want to count a number of subjects assigned to "ummu", but that same subject name appears again shouldn't be count. In this example, the count will return 4. How can I achieve this using excel formula?

How to use a VLOOKUP as a criteria in SUMIF?

First allow me to provide some background:
I have two tables, the first with one column that has a key value, which is just one letter of the alphabet and a second column with values that later I want to sum. The second table also has two columns. The first contains a list of the distinct values from the key column of the first table, and the second contains a binary value of 1 or 0. Examples below:
Table 1: Table 2:
A 50 A 1
A 50 B 0
B 100 C 0
C 125
The binary values in Table 2 are variable based on other information contained in my workbook. Now what I want to do is to sum all of the values in Table 1, where the Primary key is "turned on" in Table 2, aka the value in the second column is 1. I've tried multiple iterations of using SUMIF and VLOOKUP and LOOKUP as the criteria but can't get anything to work. Can anyone help out with a way, either using VBA or in the cell formula itself, to get this done?
Thanks in advance.
How's this? Place this next to the 1 or 0 in your Table2, =IF(F1>0,SUMIFS($B$1:$B$4,$A$1:$A$4,E1),""):
and if you drag that down, it'll return blanks for the "letter" that doesn't have duplicates.
Edit: Or, per #pnuts, this =SUMIF(A:A,"="&INDEX(E:E,MATCH(1,F:F,0)),B:B)

Resources