Find most frequent occurrence with condition on Google Sheets - if-statement

I have a list of countries and company types (A, B, C and D) in a Google Sheet. For each country, there are multiple entries, one entry per company. Countries are in column A of the spreadsheet, the type of the companies is in column B.
I would like to find out, for each country, what is the most common type of company. In other words, I would like to know, for each country, what is the letter in column B, that appears the most.
I have managed to find out what is the letter that appears the most in the entire list of countries. To do that, I have used this formula in cell D2:
=ARRAYFORMULA(INDEX(B1:B,MATCH(MAX(COUNTIF(B1:B,B1:B)),COUNTIF(B1:B,B1:B),0)))
It gives me the most common letter overall. However, I am not sure how to include a condition in the formula that will give me the answer considering one particular country only.
I have created a sample sheet, which you can find here. I have created a table on D1:E16 in which I would like to have the formula.
Thank you.

This should do it:
=ARRAYFORMULA(INDEX($B$1:$B,MATCH(MAX(COUNTIFS($B$1:$B,$B$1:$B,$A$1:$A,D2)),COUNTIFS($B$1:$B,$B$1:$B,$A$1:$A,D2),0)))

Related

If Field is Empty in Salesforce

I have a report in Salesforce where I would need to use an "if"-logic, but I don't know if it's possible.
I have two columns. Column A (object1) and column B (object2)
Column A is sometimes empty, but column B always has a value/text.
I want to apply an if-logic that says "If column A is empty, show text of column B/object 2 in that case".
Is it possible to do this?
At the end I should see a report where column A is never empty.
I appreciate any help I can get.
Read up about BLANKVALUE function. You can use it in a normal formula field (if there's clear relation between A and B) or in a report's row-level formula.
This is a terrible idea for any real application - but here's providing Account's City if Contact's City is blank.

If statement based on presence of duplicates

If the data in column A is found in multiple rows, look at the data in column C for those duplicate rows. Whichever is highest value in C, return the value from the respective row but column B. In my picture, I'm trying to populate the stuff in yellow automatically, ideally with formulas in excel. Any help is greatly appreciated.
enter image description here
My first attempt was this (a formula that you may copy on cell D2):
=INDEX($A$2:$C$9,MATCH(MAX(IF($A$2:$A$9=A2,$C$2:$C$9)),$C$2:$C$9,0),2)
This is what it does: the combo INDEX-MATCH does what VLOOKUP does, but it is more efficient than VLOOKUP. Basically it commands Excel to navigate the $A$2:$C$9 range and then find the following match:
Find the row with the MAX price for the same Item (this part: MAX(IF($A$2:$A$9=A2,$C$2:$C$9)));
Then return whatever value is on column B, at that row.
Albeit this formula seemed to work, I tried something out: what if, by some unfortunate coincidence, the MAX price for two items was the same?
This is what happens when CDE888 sells for 217
Thus, one can tell the formula above is wrong and needs a fix. This is the new formula:
INDEX($A$2:$C$9,MATCH(A2&MAX(IF($A$2:$A$9=A2,$C$2:$C$9)),$A$2:$A$9&$C$2:$C$9,0),2)
This time, the formula looks for a value that is composed of the Item code AND its highest price.
The rest works exactly as the first formula.
One last word: I wrote this formula on cell D2, then dragged the formula down.

If formula using text within a cell as search criteria

I have an excel sheet that we use to Audit employees. Data from the Audit is entered on one sheet within the workbook then a second sheet is used as our score card to tally incidents.
I am currently using various if statements (mostly countifs) that search for each employee name on the Audit sheet then match different criteria to return a count of how many times that specific employee has violated a regulation. However as employees switch, it is a very long process to manually adjust the formulas to the new names as we have a lot of employees and these formulas are being used in 5 different instances for each employee.
Here is an example of one of the formulas that I am currently using:
=countifs('17 Q1 Audits'!D3:D,"Chris",'17 Q1 Audits'!P3:P, ">0.25")
I was wondering if there is a way to tell the formula instead of searching for Chris to look a cell A52 (which is where the name Chris is listed as text only for the line) then search for whatever text is in cell A52 but complete the rest of the functions as normal.
This would make it so names in column A on the score card sheet are the only thing that need to be adjusted, the formulas would no longer need to be manually adjusted with the name.
Is this possible?
Please try:
=countifs('17 Q1 Audits'!D3:D,A52,'17 Q1 Audits'!P3:P, ">0.25")

Conditional/cascading/dependent drop-down list

I am essentially trying to do that this guy is trying to do:
Excel drop-down list using vLookup
I've gone through the steps and since my data set has about 400 different drop down options I am hoping there is an easier way than naming ranges. I have a list of about 400 different account names. Each of these account names is tied to a household and identified by the household ID number. A household can have anywhere from 1-5 account names. I would like for my drop down menu to be able to identify a household ID number and then provide the drop down with the account names associated with it.
Example:
Where household Id number is the identifier.
I've gone here as well http://sites.madrocketscientist.com/jerrybeaucaires-excelassistant/data-validation/dynamic-indirect and am trying to find a way to save on some of the manual work.I am a total newbie so thank you in advance for any help you can provide.
Let's pretend you have three worksheets. The first worksheet, Sheet1, is the sheet that your users will be looking at and it has the drop down lists. We'll say that the cell containing the first drop down option is in B1 (the one with about 400 different options) and the cell containing the dependent drop down is in B2:
On your second sheet, which we'll call MasterList, is all of the data options and the corresponding data. Row 1 is a header row; Row 2 and down is the actual data:
On your third sheet, which we'll call DropDownLists, is where the magic happens. It first needs to have a list of all the unique data options. I've put that in column A. You can get the unique data options from your master list through whatever means you prefer (Advanced Filter, Pivot Table, formula, VBA, etc). That list of unique data options is the basis of your drop down list for Sheet1 cell B1. Then in cell B2 of DropDownLists and copied down as far as needed to guarantee it will grab all data associated with the selected Data Option, use this formula (adjust sheet names and ranges to suit your actual data):
=IF(OR(Sheet1!$B$1="",ROW(B1)>COUNTIF(MasterList!$A$2:$A$10000,Sheet1!$B$1)),"",INDEX(MasterList!$B$2:$B$10000,MATCH(1,INDEX((MasterList!$A$2:$A$10000=Sheet1!$B$1)*(COUNTIF(B$1:B1,MasterList!$B$2:$B$10000)=0),),0)))
This makes your DropDownLists sheet look like this:
Lastly, we need to make that list (data based on the selected Data Option) a dynamic named range. I named it listFilteredData and defined it with this formula:
=DropDownLists!$B$2:INDEX(DropDownLists!$B:$B,MAX(2,ROWS(DropDownLists!$B:$B)-COUNTBLANK(DropDownLists!$B:$B)))
Then for Sheet1 cell B2, use Data Validation and define the list with =listFilteredData and you will get results as shown in my example.
Practice with this.....it will get what you need.
Your data will have to sorted for this to work.
Sorted Data
Data Validation for Shows
Data Validation for Episodes
This formula in the data validation box
=OFFSET($A$1,MATCH($E$4,$A:$A,0)-1,1,COUNTIF($A:$A,$E$4),1)
Enter the array formula to find the Duration
Must be confirmed with Ctrl & Shift & Enter
=INDEX($C$4:$C$18,MATCH(1,(E4=$A$4:$A$18)*(F4=$B$4:$B$18),0))

Using Index function without exact matches

I don't know the easiest way to get this done. I have 1 list of account names given to me, and a list of over 15,000 account names with corresponding sales rep names from our system. I need to know if the accounts on my list have assigned sales reps and who they are.
The way I have it set up is
Column A: System List
Column B: Corresponding sales rep
Column C: My account list
Column D: =INDEX(B:B,MATCH(C2,A:A,0))
This produces some correct results but some of the account names aren't exact which causes a problem. For example
Column A: American Services Inc
Column C: American Services
Column D: #N/A
I'm stuck on what to do now.
For the specific example presented you can do this wildcard match:
=INDEX(B:B,MATCH(C2&"*",A:A,0))
But depending on how "different" the entries in your lists are that should match, you may need an heuristics fuzzy-match add-in.