In the beginning I used this formula SUBTOTAL(3;(A14:A150>0)) and it works perfectly but now I need to add a condition that I must count the number of rows where the value in the column F is greater than 0.
This formula COUNTIF(F14:F150;">0") return the right result, but when I filter I don’t have the right one.
I tried also SUMPRODUCT(SUBTOTAL(3;F14:F150)/A1*(F14:F150>0)) it return the same thing as the COUNTIF.
You can add another column with formula:
=IF(SUBTOTAL(103;F14))
Because you are using filters this formula will help you determine if your cell is hidden or not.
Now you can use, assuming that latter formula is in column G:
=COUNTIFS(F14:F150;">0";G14:G150;">0")
Array-entered using Ctrl+Shift+Enter:
=SUMPRODUCT(--(F14:F150>0),IF(SUBTOTAL(3,OFFSET(F14:F150,ROW(F14:F150)-MIN(ROW(F14:F150)),,1)),F14:F150,""))/A1
I don't get exactly your needs but you may want to use
=SUMIFS(F14:F150,F14:F150,">0",A14:A150,">0")
or
=COUNTIFS(F14:F150,">0",A14:A150,">0")
Related
I want to use a macro to filter columns in a table. I want to filter for values that are higher than a value I want to put in cell, to be able to easily change the filter. Does someone have a trick for doing this with vba?
Many thanks, Bram
Record a macro whilst filtering a table on a column value. You would right click on the table column header of interest whilst recording the code and select Number_Filters > Greater Than and enter your desired number. That would give you the outline code. You can then amend the code to pick up the desired value from a specified cell. If applying filter to multiple columns record macro whilst doing this process over several columns.
Thank you for you answer. I tried this already, but I could not get the macro to pick from a specific cell. If I stored the value of the specific cell under as 'value' and put that in the outlined code, it would just do Greater Than value.. DO you have shortcut for this?
Thanks!
I have a sheet that shows max values spent anywhere. So I need to find most expensive place and return it's name. Like this:
Whole sheet.
Function.
Function in text:
=IFS((A6=MAX(D2:D31)),(INDEX(C2:C31,MATCH(A6,D2:D31,0))),(A6=MAX(H2:H31)),(INDEX(G2:G31,MATCH(A6,H2:H31,0))),(A6=MAX(K2:K31)),(INDEX(K2:K31,MATCH(A6,L2:L31,0))))
Basically I need to find a word left to value, matching A6 cell.
Thanks in advance.
Ok.. Overcomplicated!
Firstly, why the three rows? it's a lot easier if you just have one long row with all the data (tell me if you actually need 3 I'll change my solution)
=LOOKUP(MAX(D2:D31);D2:D31;C2:C31)
The MAX formula will lookup the biggest value in the list, the Lookup formula will then match it to the name.
Please note: If more than one object has the maximum price, it will only return the first one. The only way I can think of to bypass that would be to build a macro.
EDIT:
Alright.. Multi Column solution is ugly and requires extra columns that you can just hide.
As you can see you'll need 2 new columns that will find the highest for each row, 2 new columns that will find the value for each of these "highest" (in this case tree and blueberries) and then your visible answer will simply be an if statement finding out which one is bigger and giving the final verdict. This can be expanded with an infinite number of columns but increases complexity.
Here are the formulas:
MAX(H2:H31)
LOOKUP(A5;H2:H31;G2:G31)
MAX(L2:L31)
LOOKUP(C5;L2:L6;K2:K6)
IF(A5>C5;B5;D5)
I was playing around with a couple ideas to count unique text based on two criteria. I was thinking Sumproduct would do it for me, but it doesn't seem to work. I may need some kind of VBA script. Basically, I want to do the following.
1) Look at everything in ColumnB and if that matches a criteria
2) Look at everything in ColumnW and if that matches a criteria
3) Count unique text in ColumnF.
It's almost like this:
=COUNTIFS(W:W,A1,B:B,B1)
THEN, based on the result of that, count uniques in ColumnF
I was thinking this should be pretty easy, but it's turning out to be really hard!
You can use a standard SUMPRODUCT-based pseudo-COUNTUNIQUE but you need to modify it by adding the criteria in the numerator and also the inverse criteria in the demononator; the latter to avoid #DIV/0! errors. This will generate a pseudo-COUNTIFSUNIQUE.
=SUMPRODUCT(SIGN((B2:B20="bee")*(W2:W20="double-you"))/
(COUNTIFS(B2:B20, "bee", W2:W20, "double-you", F2:F20, F2:F20)+(B2:B20<>"bee")+(W2:W20<>"double-you")))
Another solution is to adapt the formula from here: Count Unique Text Values in a Range.
Instead of using F:F, you modify it to match F:F if both Crit1 and Crit2 hold and "No Match" otherwise. That is,
IF((B:B="Crit1")*(W:W="Crit2"),F:F,"No Match")
Then you do a unique count on that array.
=SUMPRODUCT(--(FREQUENCY(MATCH(IF((B:B="Crit1")*(W:W="Crit2"),F:F,"No Match"),
IF((B:B="Crit1")*(W:W="Crit2"),F:F,"No Match"),0),
ROW(F:F)-ROW($F$1)+1)>0))
-NOT(PRODUCT((B:B="Crit1")*(W:W="Crit2")))
The -NOT(PRODUCT(...)) at the end is to subtract the unique count for the "No Match" entry if it exists (this can be replaced by just -1 if you know there will always be things that don't match both criteria).
Note that this is an array formula and must be entered using Ctrl+Shift+Enter.
I am using an INDEX/MATCH to locate a facility number, then go to the appropriate column and return the first non-blank answer it receives. this is great. However, I can't figure out how to add a SUM function to this, so it will add all of the index match results, and not just stop at the first one it finds. I'd like to only use a formula, not VB. This is what my array currently looks like.
=INDEX(INDIRECT("$H"&(MATCH(M45,$B:$B,0))&":$H$10000"),MATCH(FALSE, ISBLANK(INDIRECT("$H"&(MATCH(M45,$B:$B,0))&":$H$10000")), 0))
Currently I have a function in VBA that finds the longest cell length in a given column. it inserts a column next to whatever given column, inserts LEN(A1) (whatever the desired column address is) and fills that down, then It uses the MAX function to find the greatest value.
Until now that's been good enough but now the user wants to know which row that greatest value is on as well. is there a way to do that without sorting or filtering?
The function is run once by the user and loops across each column, and there are about 150000 rows, so it would take a while to filter / sort 15 times.
any suggestions appreciated
=match(max(column),column,0) will give you the row number where the max occurs.
You could then use
=index(othercolumn,match(max(column),column,0)) to get some other column value for that row
Assuming values in A2:A6
This will give you row number, relative to the data range
=MATCH(MAX(LEN(A2:A6));LEN(A2:A6);0)
This will give row number relative to the worksheet
=ROW(A2)-ROW($A$1)+MATCH(MAX(LEN(A2:A6));LEN(A2:A6);0)
And this will give you the value
=INDEX(A2:A6;MATCH(MAX(LEN(A2:A6));LEN(A2:A6);0))
All those are array formulas, you need Ctrl+Shift+Enter to enter them
thanks to everyone who posted, I also found this formula: =CELL("address",OFFSET(A1,MATCH(MAX(A1:A10),A1:A10,0)-1,0)) (assuming data is A1 - A10) which will give the cells actual address as well if anyone ever wants it. heres the site for that: https://support.microsoft.com/kb/139574