I know there is already a question that has been answered about counting uniques with a condition (Count Unique values with a condition), but I want to know how to count uniques in a column with TWO conditions.
I have a dataset with dates of locations created as well as city. Each location has an owner and sometimes an owner can have multiple locations so I want to count unique owners by city and month (both already exist as columns).
How can I do this?
The formula I suggested in the link is this
=SUM(IF(FREQUENCY(IF(B2:B100=1,IF(A2:A100<>"",MATCH(A2:A100,A2:A100,0))),ROW(A2:A100)-ROW(A2)+1),1))
that counts different values in A2:A100 if B2:B100 =1
You can just add more IFs with more conditions, making sure you get the requisite number of parentheses in the correct locations, e.g. for the number of different owners by city and month try this version for March in Chicago
=SUM(IF(FREQUENCY(IF(City="Chicago",IF(Month="March",IF(Owner<>"",MATCH(Owner,Owner,0)))),ROW(Owner)-MIN(ROW(Owner))+1),1))
confirmed with CTRL+SHIFT+ENTER
To add to Barry's answer: you don't have to nest the IF's as that gets messy quickly. You can simply multiply them together like this:
IF((City="Chicago)*(Month="March"),...)
It's much easier to add variables that way and keep track of parenthesis.
If you are using Excel 2013, there is a very simple approach w/o any formulas,
Consolidate (excel feature under DATA), arrange in a way the City names are on left, and owner names next column to right, on top row put the labels of city and owner, then select the data and click both (header and left row) options, and for the operation from top of the dialogue choose count.
You should have the report you are looking for.
Note: You also might need to remove duplicates also you can do so based on two column conditions.
Related
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.
I'm using Excel 365. I have a program that exports Excel files, and one field is a bunch of tags, separated by commas.
Let's say it looks something like this:
The program allows multiple tags (there's maybe 20 that could be changed in the future) to be selected as ingredients for each kind of candy. It is not a consistent number, though they seem to always be alphabetical.
I'm looking to make some kind of table by ingredient and chef, according to time, like this:
I'm trying pivot tables, but they come back with long ingredient lists, when I really want just one item per line. I also tried making an additional column for each ingredient, which searches the main column and returns yes or no based on if it's in the ingredients column. It's still not working to have a single item listed each row with pivot tables- it gets into lots of levels and sublevels that way.
It's very likely there will be more ingredients and chefs in the future, so I'm trying to stick to some pivot tables where people can push "refresh all" to get the new ones. Ideas?
If you can build your ingredients list manually and add the names across the top then you can calculate the totals using a SUMIFS formula.
=SUMIFS($F$2:$F$5,$B$2:$B$5,"*"&$A10&"*",$C$2:$C$5,B$9)
if you put the formula above in cell B10 then autofill across and down then the values will be calculated automatically.
To break it down so you understand what's going on
=SUMIFS(**$F$2:$F$5**,$B$2:$B$5,"*"&$A10&"*",$C$2:$C$5,B$9)
is the range you want to sum under the total column. It's locked using $ so it doesn't change when you autofill.
=SUMIFS($F$2:$F$5,**$B$2:$B$5**,"*"&$A10&"*",$C$2:$C$5,B$9)
The range you want to check with the tags in each cell, also locked.
=SUMIFS($F$2:$F$5,$B$2:$B$5,`"*"&$A10&"*"`,$C$2:$C$5,B$9)
The cell containing the ingredient you want to count with a star at each end to act as wildcards so it can return true when the cell contains the ingredient. The column is locked.
=SUMIFS($F$2:$F$5,**$B$2:$B$5**,"*"&$A10&"*",**$C$2:$C$5,B$9**)
last bit is the range of the chef list (locked) and the criteria above locked by row.
I can't think of a way to automate the ingredient list but hopefully the formula will help.
Every month I get given a budget from one of our clients in a Google sheet, which I need to convert into a SQL query so it can be uploaded into our database. As the number of rows and columns changes, I want to write some formula to semi-automate the process for time saving and mistake elimination.
This budget has spends in multiple columns, which I've managed to write formulas to combine into one column, with the correct details in the columns next to it (see example links below).
How I've transformed the data so far
The issue is this budget per country and partner, then has to be split again across multiple options. This leaves me with three columns worth of spend values, that I'd really like to combine back into one column, and ideally skip out all the zero values.
I've found an array formula on this site that will skip the zeroes, but I can't get it to work on more than one column.
=IFERROR(INDEX($U:$U,SMALL(ROW(myRange)*(myRange<>0),SUMPRODUCT(N(myRange=0))+ROWS($1:1))),"")
From this Question's Answer
Is it possible to write a formula, that skips the zero values down one column, and then starts at the next? And that will also allow me to keep the correct matching details from the other columns alongside it, as well as bring in the column headers for the options as entries in a new column?
Thanks
Edit:
Here is the final format I'm looking for:
There is a concatenated field off the end that combines all the columns. Most of the values are populated by various Vlookups, to transform from the text version, into the database IDs, needed to fill the table.
It's also worth saying, that not being able to skip the zeros, is OK, as I can manually delete them fairly easily.
But as the number of countries and partners can and will change, I want the formula to be able to move column at the end of the dataset.
I have a spreadsheet of statistics from sports games over a season, for different leagues - each row holds a single event that happened in a game, such as a penalty. There are many rows of events for each individual game. One of the columns is the league, another is the home team and another is the away team. How can I count the total number of games in a given league? In other words, I would need to count the number of unique pairs of strings from Home and Away, where League = "Ligue 1".
EDIT
I have tried:
=SUMPRODUCT(1/(COUNTIFS(E2:E81078,"Ligue 1",F2:F81078,F2:F81078,G2:G81078,G2:G81078)))
which returns a DIV/0 error (it does work if I dont include the column E = "Ligue 1" criteria).
This is similar to your formula but deals with the division by zero
=SUM(IFERROR((1/COUNTIFS(E2:E81078,"Ligue 1",F2:F81078,F2:F81078,G2:G81078,G2:G81078)),0))
Enter it with Ctrl+Shift+Enter rather than just Enter. If done correctly you will see {} around the formula
Try not to use ranges that are bigger than your data because it will slow these kind of formulas down significantly
Update
This might also work if your data is ordered the way you show in your question. It counts the number of times the home team changes in Ligue 1 data :
=SUMPRODUCT((F3:F81079<>F2:F81078)*(E2:E81078="Ligue 1"))
Note that the ranges in column F are offset by one row
You can do this with a Pivot Table.
Add a "helper" column where you concatenate the two teams, preferably with a delimiter in between, eg:
=CONCATENATE(B2, "|", C2)
Use, for example Teams for the column header
Then, Insert ► Pivot Table and be sure to select to Add to Data Model
This adds the option for Distinct Counts to the Values Settings
Then Drag "league" to the Rows area, "Teams" to the Values area, and select Distinct Count for the Value Setting
You might get a table similar to below, which you can format in many different ways:
EXCEL SCREENSHOT=SUMPRODUCT(1/COUNTIFS($B$1:$B$7,B1:B7,$C$1:$C$7,C1:C7))
TRY THIS =SUMPRODUCT(1/COUNTIFS($B$1:$B$7,B1:B7,$C$1:$C$7,C1:C7))
I have an excel document with all of the cities in Missouri with their corresponding zipcode and county. Out of the 1000+ items on the list only about 500 pertain to me. I have a list of the cities I need. I have tried using the advanced filter to filter out the unwanted results, but was unsuccessful. I have been at this for hours and cant seem to get it to work. Can someone please help me figure this out?
Use a VLOOKUP in the first sheet to find the matches, then sort out the mismatches. Here are the steps
In your My Cities sheet, select all of the cities and name the range MyCities by typing it into the name box right above column A
In the sheet with the zip codes, in cell D2, enter formula
=IFERROR(VLOOKUP(C2,MyCities,1,FALSE),0)
Copy that formula in column D to the bottom of your data
In Cell D1 type in Match (so your sort will see the data set properly)
Sort on column D...the 0's should be the unwanted
I've had what looks like this very same problem for another state. My solution wasn't so high-tech as using any fancy Excel functions. The reason was that there may be no query-able patterns of names, and no patterns of zip codes. Zip codes, as you know, cross city and county and other political boundaries, so they can be a challenge. There were only patterns of counties. First I assigned names and numbers to counties, in alphabetical order. If I wanted a certain county, I simply query or sort and select by the county number (the name would work, but the number was easier). If I wanted a query by city, I could sort on the city name and select from that. Anything beyond that required specific coding. For example, if I wanted contiguous counties, I had to create a manual code for contiguousness. If I wanted only certain cities in a group I had to manually code those cities. In any case, I'd sort on whatever was the appropriate code and select the area of the list that was needed. If you already have a list of zip codes or counties or something like that, then it might be faster and better better to put your two tables into MS Access and do a join query.