I have a list of cities (this is a simplified version)
London
Manchester
Nottingham
I want to say something like (Obviously formula is not correct, is just to show what I am trying to do)
=COUNTIFS(MachineData!$X:$X,"Y",MachineData!$N:$N,"*london*" OR MachineData!$N:$N, "*Manchester*" OR MachineData!$N:$N,"*Nottingham*")
Basically, I want to count if its London OR Manchester OR Nottingham but also if X:X is Y
How can I do this without having to repeat the same instruction 3 times? is there a way to do this where I can tell it to check all the conditions for the cities at once?
Update: I have been trying something like
=COUNTIFS(MachineData!$X:$X,"Y",SUM(COUNTIFS(MachineData!$N:$N,{"London","*Manchester*","Oxford","*Nottingham*"})))
But this is not working for me
You are very close to a solution yourself. Try:
=SUM(COUNTIFS(MachineData!X:X,"Y",MachineData!N:N,{"*london*","*manchester*","*nottingham*"}))
edit: Use #JvdV solution. Far more elegant, less wall of text.
I created a small table as an example, five lines long reading london, manchester, nottingham, cardiff, london. The table name is table1, the column header I used was "target city"
With that in mind, this will bring the desired results into a single cell.
=SUM(COUNTIF(Table1[Target city],"london"),COUNTIF(Table1[Target city],"manchester"),COUNTIF(Table1[Target city],"nottingham"))
Result = 4
Warning: Depending on the length of the target cities you want to bring in and how frequently that list changes this might become prohibitively large/time consuming.
If you need something that will dynamically scale based of a changing list of cities you want to look for, something like python may be a better solution.
No, COUNTIFS is restricted to AND and cannot use OR.
=SUM(COUNTIFS(Table2[Category 2],"Y",Table2[Category 1],{"London","Manchester","Nottingham"}))
Suppose you have the following named ranges:
There are a couple of ways to crack this question:
Solution1:
=SUMPRODUCT(((N:N=City1)+(N:N=City2)+(N:N=City3))*(X:X=Criteria1))
For this type of question, I normally use SUMPRODUCT as a first instinct, but it is not as fast as using SUM+COUNTIFS if you are working on a large dataset.
Solution2:
=SUM(--ISNUMBER(MATCH(N:N,Cities,0)*MATCH(X:X,Criteria1,0)))
Instead of checking on individual cities, it would be faster to put the cities in a named range and check all of them at once and then add the results up.
Solution3:
=SUM(COUNTIFS(X:X,Criteria1,N:N,TRANSPOSE(Cities)))
This is the solution proposed by JvdV using named ranges.
Solution4:
=SUM((N:N=TRANSPOSE(Cities))*(X:X=Criteria1))
This will do the trick too, but I am not sure how it compares to SUM+COUNTIFS in terms of calculation efficiency on a large dataset.
Related
I think that it is not possible after some search, but here is my question:
I have a row of values, which correspond to a quantity we calculate every day. We alternate the experiments between product A and product B.
Now, I want to run student tests on the averages of 3 consecutive experiments, on product A versus product B. A toy example can be found below:
I would like to run a T.Test to compare the sets of values (B2,D2,F2) to (C2,E2,G2). However, nothing seems to work, at least not the following:
=T.Test((B2,D2,F2);(C2,E2,G2);2;1)
=T.Test((B2;D2;F2);(C2;E2;G2);2;1)
=T.Test({"B2";"D2";"F2"};{"C2";"E2";"G2"};2;1)
Note that I was able to get my test results by reorganizing the data so that the ranges are contiguous, but this has definitely made be curious to see if there is a solution.
For those with access to HSTACK() (or VSTACK() for that matter), try:
=T.TEST(HSTACK(B2,D2,F2),HSTACK(C2,E2,G2),2,1)
If not available, try:
=T.TEST(INDEX(B2:G2,{1,3,5}),INDEX(B2:G2,{2,4,6}),2,1)
EDIT: for those with older versions of Excel, as per #JosWoolley you'd indeed need to pursuade Excel to use arrays:
=T.TEST(INDEX(B2:G2,N(IF(1,{1,3,5}))),INDEX(B2:G2,N(IF(1,{2,4,6}))),2,1)
See this data set below. It has 3 columns (PTQ, % Growth, $ Growth) that all need ranked individually then summed up and then ranked again for a total power rank of each region. Is there any way I can do this with a single formula? I do this a lot and it would be nice not to have to rank everything individually each time. Basically I need to end up at the "Power Rank" column.
To clarify, I do not want to rank first on one column then another, they all need to be ranked equally together.
Thought I'd add a solution for non-365 users:
Edit: slight amendment so that the returned ranking mimics that of the RANK function, with thanks to #Scott Craner
=MMULT(N(MMULT(CHOOSE({1,2,3},RANK(A2:A10,A2:A10),RANK(B2:B10,B2:B10),RANK(C2:C10,C2:C10)),{1;1;1})>TRANSPOSE(MMULT(CHOOSE({1,2,3},RANK(A2:A10,A2:A10),RANK(B2:B10,B2:B10),RANK(C2:C10,C2:C10)),{1;1;1}))),ROW(A2:A10)^0)+1
which may require committing with CTRL+SHIFT+ENTER, depending on the version of Excel being used.
The static
{1;1;1}
relates to the fact that 3 columns are being queried, and could of course be replaced with a dynamic alternative.
We can use Office 365 LET and SORT. RANK does not allow the use of arrays, so we need to improvise with MATCH and SORT.
=LET(
ptq,A2:A10,
grwt,B2:B10,
grwthd,C2:C10,
ptqrnk,RANK(ptq,ptq),
gwtprnk,RANK(grwt,grwt),
gwtdrnk,RANK(grwthd,grwthd),
sm,ptqrnk+gwtprnk+gwtdrnk,
MATCH(sm,SORT(sm),0))
Problem is straightforward, but solution is escaping. Hopefully some master here can provide insight.
I have a big data grid with prices. Those prices are ordered by location (rows) and business name (cols). I need to match the location/row by looking at two criteria (location name and a second column). Once the matching row is found (there will always be a match), I need to get the minimum/lowest price from two ranges within the grid.
The last point is the real challenge. Unlike a normal INDEX or MINIFS scenario, the columns I need to MIN aren't contiguous... for example, I need to know what the MIN value is between I4:J1331 and Q4:U1331. It's not an intersection, it's a contiguous set of values across two different arrays.
You're probably saying "hey, why don't you just reorder your table to make them contiguous"... not an option. I have a lot of data, and this spreadsheet is used for a bunch of other stuff. So, I have to work with the format I have, and that means figuring out how to do a lookup/min across multiple non-contiguous ranges. My latest attempt:
=MINIFS(AND($I$4:$J$1331,$K$4:$P$1331),$B$4:$B$1331,$A2,$E$4:$E$1331,$B2)
Didn't work, but it should make it more clear what I'm trying to do. There has GOT to be an easy way to just tell excel "use these two ranges instead of one".
Thanks,
Rick
Figured it out. For anyone else who's interested, there doesn't seem to be any easy way to just "AND" arrays together for a search (Hello MS, backlog please). So, what I did instead was to just create multiple INDEX/MATCH arrays inside of a MIN function and take the result. Like this:
MIN((INDEX/MATCH ARRAY 1),(INDEX/MATCH ARRAY 2))
They both have identical criteria, the only difference is the set of arrays being indexed in each function. That basically gives me this:
MIN((match array),(match array))
And Min can then pull the lowest value from either.
Not as elegant as I'd like... lots of redundant code, but at least it works.
-rt
I have advanced Excel/Google Sheets skills. I have more of a conceptual question. I am happy with any solution (Excel or for Sheets, no difference for me).
I have a sheet where various coworkers have access and work with. It is used to define which product needs to go through which steps. Then when a part of a job is done, the status of the product is changed depending on criteria.
You can also think of it as projects and the status of a project.
The 3 examples shows how the data is input by the workers. Sometimes, the "No" cells are empty, sometimes they have a "No", sometimes for the same product, one criterion is empty, the other has a "No".
If I do a nested IF formula, I would have to create 32 of them (I believe, since its 5 criteria with each 2 options).
Obviously I can do that. I was wondering anyone has a better solution for me? Something more practical.
Thanks in advance!
Based on the data you've provided, it looks like your statuses are based on the number of Yes's in the input columns. Also you don't have a status shown for zero Yes's so I'll make an additional for that.
Given that assumption you can use a combination of the COUNTIF function (to count the Yes's), and the IFS function (to manage nested Ifs better) to drastically reduce the size of your function.
To make this cleaner I suggest you add a column and hide it containing: =COUNTIF([InputCriteria1to5Range],"Yes")
For the next formula assume the formula above is in B2. In your status column put the following:
=IFS(B2=5, Status1, B2=4, Status2, B2=3, Status3, B2=2, Status4, B2=1, Status5, B2=0, Status6)
Solution: Thanks to all for your help, I ended up firstly, creating ALL scenarios. This was actually the most complex part. See https://www.mrexcel.com/forum/excel-questions/654871-how-generate-all-possible-combinations-two-lists-without-macro.html (Answer from "Tusharm") where I had to repeat this process 5 times to have all possible outcomes. In the end, there were 192 combinations.
Then, I assigned a status for each combination.
Finally, for each product/row, I created another column where I concatenated the different criteria so that it looks exactly like my above combinations. Then finally index match the concatenated criteria to my combinations.
Ok so, twice a month I receive a large file of about 100 rows, which contains 4 columns:
Building name - value - county - state
I´ve to complete 2 other columns based on a master list that have thousands of entries.
I want to produce something very similar to this fabulous add-in (http://www.microsoft.com/en-us/download/details.aspx?id=15011), but a bit simpler and that I could use at work without problems.
What I need to do is the following:
In order to match my input with the master file, I know the county and state must match, but then, the building names can change a bit in each file for the same building (ie "John Miller #34" can be "Miller, John 34 A"), and that the values may vary but not too much.
Based on that, I want to bring from the master to my file, all the entries that may match each of my rows, filtering by County and State first, and then by similarity in name and value.
Could you please share your thoughts on how you´d approach this?
I know this is not a simple thing, but anything may help!
You could also use wildcards to try and match on the primary identifier within the name. from your example, that might be "Miller", for example.
Unfortunately for you, the vlookup "fuzzy logic" is nowhere near reliable for your purpose (see the comment on my answer below for details), and you won't have any indicator as to whether the returned result is accurate or not.
It's possible to get 100% of what you want through some heavy coding in a user-defined function, but this is probably well beyond your comfort zone.
A clunky solution, although somewhat easy to explain and adopt, is to create an "identity column" for every unique scenario that can occur. So, for example:
Then you can import your master sheet and add the same identity column to the left, and perform your vlookup. When a new configuration is added you can just add that to the master list and it will populate in your imported file in future instances.
That said, if you are interested in learning, there have been many people who have walked in your shows and felt your pain. You may want to indulge in this:
http://www.mrexcel.com/forum/excel-questions/195635-fuzzy-matching-new-version-plus-explanation.html
Because what you are truly requesting is an algorithm. It's not a simple thing, but it's very possible. And if you take the time to learn you not only solve your immediate problem, but make yourself marketable as an Excel wiz. Good luck!