Count unique value with 2 criteria from 2 row - excel

Can you help me to solve this problem?
I have two row with different value each row like this:
I want to count how many city with name london but only count if the Name if different, so from the table above the result count is only 2 london.

You can use a pivot table as a step to help:
Select the data and set up the pivot table:
Change the design of the table to set:
a. Report layout to tabular form
b. Report layout to repeat all item labels
c. Subtotals - do not show them
then the pivot table should be like this:
Finally, you can use COUNTIF. In my example, I have put the city name in G2 and referencing it in the formula:
=COUNTIF(D:D,G2)

You first need to group both columns
=COUNTIF(UNIQUE(A2:B14),"london")
COUNTIF count cells based on one criteria

Related

How to sum over criteria in Excel?

Let's say I have a table of First/Last names and Salaries.I want to compute, for every last name, the sum of the salaries of people with that name.
I know how to do that for each name individually using SUMIF, but I was wondering if there is a quick function to produce a table of Last names and Salary sums?
Another option would be using a pivot table.
On the insert tab, select pivot table
Use your existing table as the data
In the fields select the Last Name and Salary columns
Let's support you have the salary sheet in sheet1 as below,
copy column last name value to sheet2.column A, remove duplicate, add a new column as Salary Sum in column B, input a formula as =SUMIF(Sheet1!B:B,Sheet2!A2,Sheet1!C:C) and drop down to all rows, then you can got a salary sum table as below,
of course, if the first name/last name is dynamic and unexpected, it would doesn't work. you can drop a button and bind a VBA code to handle it.
You could use this ARRAY FORMULA: CTRL + SHIFT + ENTER
=IFERROR(INDEX($A$2:$A$7,MATCH(0,COUNTIF($D$1:D1,$A$2:$A$7),0)),"")
For summing up the corresponding values just use
=SUMIFS($B$2:$B$7,$A$2:$A$7,D2)

Equivalent of SELECT FROM WHERE on Excel

I have a dataset on an Excel table in which each line has an Id and several other columns.
in some others sheets I need to select some columns depending on the given id.
I am using Excel 2016, so I've tried the "dget" function but it seems not to be the best solution.
For the dataset it's close to this:
id Name birth date gendre
1 Sara 10/05/1997 F
2 Edward 01/08/1994 M
3 Anna 06/10/1993 F
and for getting data I use
=DGET(Table1[#All];Table2[[#Headers];[Name]];A1:A2)
in each column (A1:A2 here is for id and 2)
id Name salary
2 Edward 5000
and then I add some new columns that I don't want them to be in the first dataset.
This solution works only for the first row since it requires a the Criteria (last field in DGET function) to be a range, the official definition:
Criteria Required. The range of cells that contains the conditions that you specify. You can use any range for the criteria argument, as long as it includes at least one column label and at least one cell below the column label in which you specify a condition for the column.
Starting from the second row the Criteria is not a range anymore it is like "A1;A3" (for the 1st row "A1:A2")
Is there any other solution or alternative to do so?
Select a cell in the Table, click Insert>PivotTable, then drag the ID, Name, BirthDate, and Gender fields into the ROWS area. Then add a Slicer on ID, Name, and Salary by clicking in the PivotTable and selecting Insert Slicer. Then choose the ID/Name/Salary values you want. To make multiple selections, hold down Ctrl or click the MultiSelect button of the Slicer.

Excel Count unique value multiple columns

I have a workbook with multiple sheets. On sheet1 I would like to count the number of times person in column A has a particular entry in Column C that meets criteria of column D = Content but only count if column B is a unique value.
Using the below formula I can do everything except only counting unique numbers in Column B. I enter this formula in Sheet2 C2 then pull across to I2 then pull down to 6 in each column.
=IF(COUNTIFS(Sheet1!$A$2:$A$150,Sheet2!$B2,Sheet1!$C$2:$C$150,Sheet2!C$1,Sheet1!$D$2:$D$150,"Content")=0,"",COUNTIFS(Sheet1!$A$2:$A$150,Sheet2!$B2,Sheet1!$C$2:$C$150,Sheet2!C$1,Sheet1!$D$2:$D$150,"Content"))
I am using the double countifs to not show 0's.
Here is what it looks like for Sheet1
Here is how I would like Sheet 2 to look
Any help or advise would be much appreciated.
The answer by Vijayakumar works. In case you need a simpler version (without the data model option, use this formula in column E dragged down
=SUMPRODUCT(--($B$1:B1=B2))>0
Select all data
Insert ->Pivot table
In The Pivot table fields Move "SR" to Rows section "Stage" to column section "Prod" & "IsUnique" (Col E) to filter section and "QN" to Value section
Now right click on some cell in Pivot which shows sum/count of QN Summarize
values by -> Count
In the filter section of pivot (first row on
pivot table which states "Prod"), choose "Content"
In the filter section of pivot (Second row on
pivot table which states "IsUnique"), choose "TRUE"
When you have new data, you just need to Change Data Source from the Pivot Table tools->Analyze or Refresh. However you can record this whole process as macro to automate it.
You can achieve this via Pivot table.
Select all data
Insert ->Pivot table
In the pop up ensure you check the check box at the bottom with description "Add this data to data Model" and then click OK. This will create Sheet 2 for you.
In The Pivot table fields Move
"SR" to Rows section
"Stage" to column section
"Prod" to filter section
"QN" to Value section
Now right click on some cell in Pivot which shows sum/count of QN
Summarize values by -> More optins
In the pop up, scroll to bottom and click on "Distinct Count"
In the filter section of pivot (first row on pivot table which states "Prod"), choose "Content"
Note: Distinct count won't appear in values section if step 3 is missed out. Hope this helps.

Assign a unique number to every unique product number in excel

I have two sheets. Sheet1 has a list of products and Sheet2 has a list of products and their location. Since the product can be in multiple locations, there are a good amount of duplicates in Sheet2.
There are 26,000 products. I have assigned each product a number in Sheet1, 1-26,000. Is there a way for me to assign each number to the correct product in Sheet2?
This is a example of what I need:
The top table would be Sheet1 and the bottom table would be Sheet2, the one with duplicates.
This is what they look like right now:
Sheet1:
Sheet2:
Please let me know if I did not explain this well enough. I appreciate your help!
copy your column A in sheet 1 to column c
Then in your sheet 2 column C row 2, use =vlookup(B2,'sheet1'!B:C,2,0)
(if your first item is in B2)
Drag your formula down and it should work.
Use VLOOKUP or the INDEX MATCH combo formulas in the second sheet to locate the ITEM IDs in the first worksheet
If you're Item ID's are sorted the way you illustrate it, then you can simply use an IF formula:
For example you have a data as shown:
Enter this formula in A2:
=IF(B2=B1,IF(ISNUMBER(A1),A1,1),IF(ISNUMBER(A1),A1+1,1))
Above formula will give you what you've described.
Again, your items should be sorted so that same Item ID are in order.

Excel formula to output name in first column based on a value in the 3rd column

I have a data table with 8 columns and i want to know if anyone can help me come up with a formula to get the name in the first column if i enter a value into the columns (3,4,5,6,7,8).
I want the name from the first column to appear in another table on another sheet where only names appear where data is in the columns (3,4,5,6,7 & 8)
Try this:
=IF(OR(Sheet1!C2<>"";Sheet1!D2<>"";Sheet1!E2<>"";Sheet1!F2<>"";Sheet1!G2<>"";Sheet1!H2<>"");Sheet1!A2;"")
You can use C1 = 1 .... if you prefer.
And C1,D1,E1... have to be replaced with your columns.
Also Sheet1 have to replaced with your sheet name
I would use a Pivot tables.
First create a new column in the existing table:
If you only having positive values then it is:
=sum(C2:H2)
If you have zero and negative values as well it would be like this:
=IF(COUNTBLANK(C2:H2)=6;0;1)
Then make a pivot table with the "TO/TA name" in the Row Labels and the new column in Report filter - where you then removes the "0".

Resources