How to count unique records in a column that have a value in another column - excel

I have this issue: here is my table
ColA ColB
te Y
te Y
alo
te Y
te
bb Y
aa Y
I want to count how many records in ColA, which has value "Y" in Col B. and if two duplicate record in A that also have same Y then just count one. (in this case, te record we just count one time)
Many thanks

I am not sure is there is a simple formula to achieve what you want, though it may be possible with an array formula of some kind.
The simplest way in my view would be:
Select your data
Select Data > Filter > Advanced Filter
Check the Unique Records Only checkbox
Select a range you would like to copy the results to in Copy to
Now hit OK
Now use =COUNTIF with criteria =Y to get number of unique records that also have Y
Edit - Array Formula Solution
I did some googling and found a site that shows how to return unique rows using an array formula. See here.
We can use that to return all unique rows in your rows in columns A and B, including rows where column B is blank. (I assume your data is in cell A2:B8)
=SUM(IF(((MATCH(A2:A8&B2:B8,A2:A8&B2:B8,0)) >=(ROW(A2:A8)-(MIN(ROW(A2:A8))-1)))=TRUE,1,0))
Once we know the total number of unique rows, if we subtract from that number the cells in column B that are blank (i.e. not equal to Y) then this should give us the total number of unique rows that have a Y in column B. We can now update the above formula as follows:
=SUM(IF(((MATCH(A2:A8&B2:B8,A2:A8&B2:B8,0)) >=(ROW(A2:A8)-(MIN(ROW(A2:A8))-1)))=TRUE,1,0)) - COUNTIF(B2:B8,"<>Y")
Type this formula in C1 and then press CTRL + SHIFT + ENTER as this is an array formula.
I tested this and it seemed to work ok.

Related

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)

Excel - how to look in a dynamically changing range of multiple rows and columns and retrieve data

I have 2 excel files. 1 is a workfile in which I work, the other is the output of a database. See pic 1 for my database output (simplified).
What we see here:
The purchase order numer in column A
The row in the database in column B
The status of the row in the database in column C
The classification in column D, where W means a product we want to measure and P meaning delivery costs, administration costs etc (we don't want to measure this)
The number of items ordered and the number of items delivered in column E
The company name and product info in column F
Now, what I want, is something like this:
I want this table to be filled automatically based on the database output. It works for column B, but I'm stuck on column C, D and E.
What I want from you!
I need help with column C, D and E.
Number of rows: it needs to calculate the rows only with W in column D. So for item 4410027708 it has to be 2 (only 2 rows with W) and for item 4410027709 it should be 1.
Items ordered: it needs to add-up all the values that are directly to the right of the W in column D. So, for 4410027708, it needs to add up 3 and 5. It must ignore all the rows with P!
Items to be delivered: You may already guess this, but it needs to add up all the values in column E that are on the same row as column C with To be delivered, but only for the W rows (not the P versions). So, for item 4410027708 this should be
I suggest easy if ColumnA can be filled down first (including for the last entry) then assuming the database output sheet is called Sheet1, in:
C2: =COUNTIFS(Sheet1!A:A,A2,Sheet1!D:D,"W")
D2: =SUMIFS(Sheet1!E:E,Sheet1!A:A,A2,Sheet1!D:D,"W")
E2: =SUMIFS(Sheet1!E:E,Sheet1!A:A,A2,Sheet1!C:C,"To be delivered")
copied down to suit.

Any ideas on how to turn certain cells absolute?

Here is my spread sheet:
What I'm trying to do is break down my total weight into individual weights, to do this I have to make total weight absolute so I can multiply my % ratios. Only problem is some skus have 6 items some have 5 items so I can't just set every X rows make absolute. essentially I want to do this.
P.S. I have about 5000 rows so it'd take a really long time to manually do it. Wondering if there's any solutions thanks.
You could use nested if functions, it's dirty but it works:
The function goes in J column
Check if the associate H column is empty
If it is empty return empty to keep the spreadsheet clean
If it is not empty check the row above in I column for empty
If it is not empty that the total weight to multiply the ratio by the total weight
If it is empty check the row above that
And repeat as necessary.
I wrote this function that checks 5 deep I think? You could keep nesting it to check 10 deep, 20 deep, etc., until you reach the nested IF limit in excel which I think is 255 so that it adapts to your varying needs in the items list.
=IF(H7<>"",IF(I6<>"",H7*I6,IF(I5<>"",H7*I5,IF(I4<>"",H7*I4,IF(I3<>"",H7*I3,IF(I2<>"",H7*I2))))), "")
Not sure if you just want the J column filled based on the H column, but here's my suggestion. I tend to use hidden columns as they keep my formulae simple but you can incorporate the formula in my G column (the column I'ld hide) into my formula in the F column.
Results Shown
Formulae Shown
P.S. I need reputation as I need to comment on another post.
Sryn
You could use a hidden column with nested If statements, formula goes in Column K:
Check if Column F is blank
If it is not check if the row above is blank
Repeat
Once the row is blank you know you are on the row with the total weight
Set the Column K cell to that value (the I column)
For column J:
If Column K is 0 then return empty
If not multiply Column H by Column K
The formula for Column K is:
=IF(F22 <> "", IF(F21 <> "", IF(F20 <> "", "", I20), I21)) - just add the required amount of nesting, for your case 6 nests is enough
The formula for Column J is:
=IF(K22 = 0, "", K22 * H22)
And then just right click column K and choose to hide that column. Of if you use column K in another part of your sheet just select any unused column.

Calculate Occurrence Number - Excel

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)

How to get uniques in column A and totals from column B?

I have a spreadsheet that looks like this:
A B
DeptA 10
DeptB 5
DeptA 5
DeptA 10
DeptC 5
DeptB 10
DeptA 20
DeptB 5
I'm trying to get a list of the unique values in A, and then the total in B for each unique value. The output I'm looking for is this, which can go in columns C/D (or wherever, doesn't matter)
DeptA 45
DeptB 20
DeptC 5
I know I can pull the uniques in A and place them in C with the following array formula:
=INDEX($A$2:$A$8, MATCH(0, COUNTIF($C$1:C1, $A$2:$A$8), 0))
How to list the column B totals along with it?
No formula is necessary.
For example, uniques may be obtained (avoiding COUNTIF, INDEX and MATCH) with Data > Sort & Filter – Advanced , Copy to another location selected, Unique records only checked and Copy to: set to C1 (though my version is a bit temperamental and at present also requires deleting C1 and sorting).
But with sorting (select A:B, Data > Sort & Filter – AZ) then subtotal can be used (insert a new row as Row1, select A:B Data > Outline – Subtotal, OK , OK [defaults are probably as required: At each change in: (Column A), Use function: Sum, Add subtotal to: (Column B), Replace current subtotals, Summary below data] then click on small ‘2’ at the top left.
Grand Total is a bonus.
You might want to use the DSUM Function as it's less work than pivoting.
EDIT: Corrected URL
You can keep your current construct and do a sumif or sumifs (they have different order of the arguments) in column D based on column C that sums column B.
Alternatively you can use a pivot table to get the complete result for you. Note however that a pivot requires manual refreshing, where the formulas will auto update when calculation is set to automatic

Resources