Count unique text values based on criteria in other column - excel

I have two columns titled "Company" and "Department", example below. The third column is what I would like to create, but I am unsure how. I want the third column to show the number of departments for a given company, and only show that number in the first reference to the company.

Try this in D2 and fill down.
=IF(COUNTIF(A$2:A2, A2)=1, SUMPRODUCT((A$2:A$999=A2)/(COUNTIFS(B$2:B$999, B$2:B$999&"", A$2:A$999, A2)+(A$2:A$999<>A2))), "")

If you create a helper column in Column C that concatenates your two cells, you can then use a function like this:
=if(countif($C$1:C7,C7)=1,sumif(….),"")
If that's not an option, you'll need to use an Array which is likely not something you want to do either.
You might be able to capture your requirements with a pivottable too... Not sure.

You could use a pivot table to get distinct count of column department.
While creating the pivot table you need to add the table to the data model so that you expose "distinct count"
(one of numerous sources: http://www.howtoexcelatexcel.com/formulas/excel-tip-how-to-count-unique-items-in-excel-pivot-table/)

Related

Two way lookup within a sortable/filterable Excel table

I am looking to return the intersection of a given row and column in an Excel table, where the sort/filter of the table will be changed.
I have found lots of resources on how to do a two way lookup in a static Excel 2D array/table that will never change order, but I am running into trouble trying to reference these intersections of a given row and column in a table that will be filtered and sorted by users. Filters and sorts are changing the cells' locations, breaking my references.
Ideally, the solution should look something like this:
=INDEX(TABLE,MATCH("PRODUCT",A:A,0),MATCH("COMPANY",$1:$1,0))
or, something like this,
=TABLE[[#Data],[PRODUCT] TABLE[[#All],[COMPANY]]
My environment is a table where the left most column is a list of products, and the top most row are column headers listing company names. The cell values at the intersection are quantities of products per company.
Thank you for any help, in advance!!
EDIT: Here's a visual example,
PRODUCTS COMPANY A COMPANY B
PRODUCT #1 1 2
PRODUCT #2 3 1
Referencing "COMPANY B", "PRODUCT #1" would return 2-- what's key is that the reference isn't broken by the table being filtered or sorted.
The first formula works, if made to select adjacent cell.
=INDEX(TABLE,MATCH("PRODUCT",A:A,0)-1,MATCH("COMPANY",$1:$1,0))
Revisiting later, it was selecting cell underneath the intended. Weird. Not positive why, but seems no one really took a look here. Folks at /r/Excel understood, though without any ideas as to why it picks cell below intended.

How do you count the occurrence of same data set in two columns-set in excel?

How can we count the occurrence of each set of data? For eg I want to check how many time the customer country in column A comes alongside country in column B ie (How many times Australia-Australia occurs in column A and column B?). The result for unique occurrences are place in right hand side of the sheet. I have found out unique occurrences of the sets and want to count how many times each occur.
You asked for a formula, but a pivot table can do the same thing faster; and without requiring you to create the table for unique countries (option found under insert, usually the first button in the ribbon):
This is how it looks like after pulling the fields in the right 'boxes', the 'Tabular' report layout is selected and the subtotals turned off.
You can make 'Australia' repeat itself too under report layout if so you wish.
Again, SUMPRODUCT is your friend:
=SUMPRODUCT(--(($A$2:$A$11&$B$2:$B$11)=(D2&E2)))
You can use COUNTIFS function as below.
=COUNTIFS(A:A,D2,B:B,E2)
Adjust the ranges to suit your data and copy down.

Which tool can be used to extract and group rows and do the summation?

I have the following table:
I would like to extract and group the table using the columns 'ELEMENTID', 'FID_waterdemand2044' and 'Demand' as shown in the figure below. Also i need to sum the Demand values. What tool can be used for this purpose in excel?
I would use Pivot table (Insert/Pivot table) and select the fields as in the picture, and then add a sum for the rightest column (Sum of Demand) manually
This setting will cause this: (I only filled two rows from your data)
So, based on assuming your data starts in cell A1, then the following will work to sum data per Element_ID:
=SUMIFS(F2:F13,D2:D13,31)

Excel formula for counting the number of incidents of a word in a column?

Is there a quicker way of searching for terms without typing each one into the formula? Like, say I have a column that has a bunch of names of locations and I want to find out how many times each one comes up.
This is the formula for when I type in the locations:
=COUNTIF($F$2:$F$274,"*AD library*")
I just modify the AD library to the next one, say monastery so it would be
=COUNTIF($F$2:$F$274,"*monastery*")
Is there another way of getting the same info without having to type in each one (it's a big sheet with a lot of locations).
Thanks
use PivotTable on just that one column. Put that column in both rows and Values:
Go to the insert tab and insert a pivot table.
Then drag the header (locations?) you want the count of to row labels and any other header to the value field (preferably something with text).
Now the pivot should give you the count of each item.
If you don't have a column with text then choose any other and you need to switch from sum to count in the value field settings.

Restructuring data in excel

I am trying to condense data in a specific way. I want any occurrences of the number 1 in each column to show up as 1 (regardless of how many times it occurs) with the corresponding site, in the corresponding column. Some sites occur multiple times in the original data, and I want to make it so that only one of each unique site shows up in the resulting data table with a 1 for the corresponding column if there any 1's in the column from the original data.
I would think it would be a vlookup function, but I have tried many different things and I am really stuck on this.
Image of original data and what I am trying to do:
Thank you
This assumes that your data set only contains 1 or blank and this approach uses a Pivot Table with MAX function. Below are details in case anyone doesn't know Pivot Tables.
Select a cell in your data and insert Pivot Table. Note, I added a title for column A, as you need that in the Pivot Table.
Click in the created Pivot Table and the PivotTable Fields dialog should pop up. If not, right click in Pivot Table and select Show Field List.
Drag the Field names (Code, a, b,& c) down to the appropriate blocks below. (Values under Columns will be created for you.)
Click on the drop down arrow next to each field name and select Max. That will rename it to "Max of ...". If that bothers you, then you can type the name you want into the Custom Name field. Note, it will not let you type the same name as the field name, eg a, but it will work if you put a space in front of it.
Given that the Pivot Table would be a lot of work for a large number of columns, here is a formula based approach. Put this formula in cell G2, then drag it down and across to fill your new table.
Note, you will have to populate all codes that you have in column F. And if any new codes are added later you will have to keep this updated. One of the advantages of a Pivot Table is that it will do this for you.
I know that you won't be putting this in these cells, so adjust accordingly. In fact, I would recommend this be in another sheet.
=IF(COUNTIFS($A:$A,$F2,B:B,1)>0,1,0)
COUNTIFS($A:$A,$F2,B:B,1)
This will count each occurrence when the value in column A matches your code $F2 AND the value in column B equals 1.
If that count is >0, then you know that at least one match was found and the IF will return 1, otherwise 0.

Resources