Month, Year and Countif - excel

I am trying to develop a query which should pick out and count the data from a data pool corresponding to the year/month in the given (A106) cell.
While such (array) construct works:
COUNTIF(IF(MONTH(INDEX(Data.$A$1463:$A$1827))=MONTH(A106);Data.$B$1463:$B$1827);">0");
such one - does not:
COUNTIF(IF( MONTH(INDEX(Data.$A$1463:$A$1827))=MONTH(A106) and YEAR(INDEX(Data.$A$1463:$A$1827))=YEAR(A106));Data.$B$1463:$B$1827);">0")
It there anything to be done about it or it is impossible?

I believe that you might want to use a sumproduct for this (though there are certainly other ways to achieve the same result). This might do the trick:
SUMPRODUCT((MONTH(INDEX(Data.$A$1463:$A$1827))=MONTH($A$106))*(YEAR(INDEX(Data.$A$1463:$A$1827))=YEAR($A$106)))

Related

Can I use MINIFS or INDEX/MATCH on two non-contiguous ranges...?

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

Define Status depending on Criteria

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.

Looking at multiple values with one statement w/o OR statement

Say I have multiple tasks: quoting, binding, rating that have same response time of 3 hours... I was wondering if there was a way to make an IF statement such that I could just say for example:
=IF(B2="*Quoting,Binding,Rating", C2+3, NA)
I haven't been able to get it to work, and I'm trying to avoid using an OR statement with the IF statement to get the values, but is it possible to do it this way? It sounds simple, "If it's task x,y,z then add 3 hours to the start time column (C2)". Any advice guys? Thanks!
This may achieve what you're after
=IF(NOT(ISERROR(SEARCH(B2,"Quoting,Binding,Rating"))), C2+3, "NA")
Hope that helps
Use the OR statement: =(IF(OR(B2="Quoting",B2="Binding",B2="Rating"),C3+3,NA()))
If you're looking to shorten the formula, you can put the values you want to check into a named range (I used "List" to reference "I:I" but you could put the list on another sheet) and use SUMPRODUCT.
=IF(SUMPRODUCT(--(B2=List))>0,C3+3,NA())

How to optimize COUNTIFS with very large data

I would like to create a report that look like this picture below.
My data has around 500,000 cells (it will continue to grow larger)
Right now, I'm using countifs function from excel but it takes a very long time to calculate. (cannot turnoff automatic calculate)
The main value is collected as date and the range of date is about 3 years, so I have to put a lot of formula to cover all range of value.
result
The picture below is the datasource the top one cannot be changed. , while the bottom is the one I created by myself (can change). I use weeknum to change date to week number.
data
Are there any better formula or any ways to make this file faster? Every kinds of suggestions are welcome!
I was thinking about using Pivot Table, but I don't know how to make pivot table from this kind of datasource.
PS. VBA is the last option.
You can download example file here: https://www.mediafire.com/?t21s8ngn9mlme2d
I will post this answer with the disclaimer that it is entirely dependent on the size of the data set. That turning on and off the auto calculate is the best way, but your question doesn't let me do that, so keep reading.
Your question made me curious, so I gave it a try and timed it. I essentially set up two columns of over 100,000 rand numbers choosing from 1-1000 and then tried to do a countif on the two columns if they were equal. I made a macro that I can run that turns off the autocalculate, inserts the start time, calculates, and then inserts the finish time. I highlighted in yellow the time difference.
First I tried your way, two criteria, countifs:
Then I tried to combine (concatenate) the two columns to see if I could make it easier by only having one countif criteria and data set. It doesn't. see result below:
Finally, realizing what was going on. I decided to make the criteria only match the FIRST value in the number to look for. I was essentially reducing the number of characters to check per cell. This had a positive result. See below:
Therefore my suggestion is to limit the length of the words you are comparing in anyway possible. You are mostly looking at dates, so you might have to get creative, but this seems to be the best way possible without going to manual calculation.
I have worked with Excel sheets of a similar size. Especially if you are using the data on a regular basis, I would heartily recommend switching to a proper database SQL based, Access, or whatever fits your purpose. I does wonders for the speed and also you won't run into the size limits of Excel. :-)
You can import the data you have now fairly easy.
I am happy as a clam with my postgresql db.

case statement in a spreadsheet

So,
what i am trying to accomplish here is pretty straight forward, i have a column fare in my spreadsheet and i want to add anew column that would say if the fare is <10 ,10<20,20<30,30+
I came up with this solution but it seems like it is not using a shortcut condition, is there a case statement or any other method i can use to achieve what i want?
=if(J19<10,"<10",IF(AND(J19>10,J19<20),"10<20",IF(AND(J19>20,J19<30),"20<30","30+"
)))
Try something like this:
=ROUNDDOWN(A1,-1)&"<"&ROUNDUP(A1,-1)
Since the conditions in a nested set of if functions are evaluated consecutively, you do not need to repeat previous conditions using and. Also note that your original formula doesn't do the right thing at the borderlines, e.g. if J19=10.
So although Excel does not have a case function, the following is simpler and more accurate than your original:
=if(J19<10,"<10",IF(J19<20,"10<20",IF(J19<30,"20<30","30+")))

Resources