Im trying to make sum.ifs formula to sum values in one row based on criteria.
In Criteria for Z I want to sum ALL Zs in table and same for D criteria.
Can I use sort of sum.ifs(A1:C1:E1;B1:D1:F1;G1) function? Unfortunately A1:C1:E1 trys to take range, not single cells and I get error...
What about this: (ugly but working)
=SUM(IF(A3:E3="Z",OFFSET(A3:E3,0,1),0))
It just goes over all cells (even the ones with the values are checked if they equal "Z", but as this is not the case (as they are values), they are skipped).
Edit (better formulated than the first one):
Next proposal:
=SUM(IF($A3:$E3=F$2,OFFSET($A3:$E3,0,1),0))
The dollarsigns are meant for fixing rows and/or columns:
$A3:$E3 : we will always be working with columns A to E, but the rows may change.
F$2 : the criteria are always on row 2, but some are in column F ("Z")
and some in column G ("D").
Place this in G3
=SUMIF(A3:E3,{"=Z","=D"},B3:F3)
The range A3:E3 is checked for the criteria of "=Z" and "=D" in turn, and the range over B3:F3 is then summed.
If you have Office 365 you could use: =SUM(FILTER(B3:F3,COUNTIF(G2:H2,A3:E3)>0))
Not sure if you wanted all summed at once or per letter. To have sum per letter use:
=SUM(FILTER(B3:F3,COUNTIF(G2:H2,A3:E3)>0)) and drag to the right
Related
I'm trying to do something similar in vba which I have an idea of only in python for loops. Can someone teach me how to do this in vba, either in function or module macro please :
For each distinct values in column A4:A30, there should be no more than 9 distinct values in column C4:C30. If true, return 'OK' in cell A1. if false, return 'Error' in cell A1'
e.g As in the picture, Sam should not have more than 9 distinct fruits. Same goes to Mary
Update :
I have tried the filterxml method and unfortunately didn't seem work for me : [1] https://i.stack.imgur.com/cbmTs.png
Solution for excel with filter/unique formulas
Easiest way to achieve it in Excel365 is: add extra column which counts unique values (Fruits) for each Key (Names) and find maximum value in this column
Start with formula that find each non-blank which fits the key.
=FILTER($C$4:$C$30,($A$4:$A$30=A4)*($C$4:$C$30<>""))
Then delete duplicates:
=UNIQUE(FILTER($C$4:$C$30,($A$4:$A$30=A4)*($C$4:$C$30<>"")))
Then check how many cells we have in filtered data without blanks and duplicates:
=COUNTA(UNIQUE(FILTER($C$4:$C$30,($A$4:$A$30=A4)*($C$4:$C$30<>""))))
Then expand our new-column (column B in my case) formula to each row in our Keys.
And finally add formula to A1 which checks maximum counter:
=IF(MAX($B$4:$B$30)<10,"OK","Error - to many velues")
*There is a little typo, it should be "Error - to many values" =)
Below how the worksheet looks in my testfile
Solution for older versions of excel
I've checked if i am able to make it works without these formulas and it is possible:
We need to start with counting if there is for key-value above current row
=COUNTIFS($A$4:A4,A4,$C$4:C4,C4)
In case we have duplicates above, they should be already counted so we skip them:
=IF(COUNTIFS($A$4:A4,A4,$C$4:C4,C4)>1,"",1)
Now we have colum with "1" or blanks. In that case we need to count each non-empty cell above which correct key (name) and add 1 so instead "" and "1" we will have "" or 1, 2, 3, 4, ...
=IF(COUNTIFS($A$4:A4,A4,$C$4:C4,C4)>1,"",COUNTIFS($A$3:A3,A4,$F$3:F3,">0")+1)
Edit
I have added one extra IF to skip keys if value is blank:
=IF(C4="","",IF(COUNTIFS($A$4:A4,A4,$C$4:C4,C4)>1,"",COUNTIFS($A$3:A3,A4,$B$3:B3,">0")+1))
Cells Formula in A1 is the same
=IF(MAX($B$4:$B$30)<10,"OK","Error - to many values")
Quick Note:
Some formulas have range which starts on 3rd row instead of 4th; Its intended because we are counting cells above and at first row of data we need to have choose something above. This code assumes that you don't have numbers (on column B) or names (on column A) in row 3;
Below I am attaching screen with example; This screen have additional columns (D-F) which isn't required, its only do display how final formula was created.
I want to perform this SUM function in every row if the value in G is unique; if the value is a duplicate then fill the cell with $0
Here is my SUM formula :
=(SUM('Base Calculator'!$K11:$Y11)*'Base Calculator'!$I11)+'Base Calculator'!$J11)
The values in Column "G" aren't sorted.
The value is Column "G" is Text - e.g., "D01"
This is as far as I have gotten with experimentation:
=IFNA($G11=INDEX(Fact1, MATCH('Base Calculator'!$G11,UNIQUE(Fact1,0,TRUE),0),1)+1,(SUM('Base Calculator'!$K11:$Y11)*'Base Calculator'!$I11)+'Base Calculator'!$J11)
*Fact1 is named range of Column G.
Sample data:
Thanks for your time and attention.
The following formula can be used to sum up with condition of uniqueness:
=(SUM(A1:F1)*I1+J1)*--(COUNTIF($G$1:$G$10,G1)=1)
EDIT
If I understand correctly, you need sum duplicate values too, but only once. Then a small change to the existing formula will do that:
=(SUM(A1:F1)*I1+J1)*--(COUNTIF($G$1:G1,G1)=1)
The blue columns is the data given and the red columns is what is being calculated. Then the table to the right is what I am referencing. So, F2 will be calculated by the following steps:
Look at the Machinery column (D), if the cell contains LF, select column K, otherwise select column L
Look at the Grade column (E), if the cell contains RG, select rows 4:8, otherwise select rows 9:12.
Look at the Species column (A), if the cell contains MS, select rows 5 and 10, otherwise.......
Where every the most selected cell is in columns K and L, copy into column F.
Multiply column F by column C.
I don't want to make another column for my final result. I did in the picture to show the two steps separately. So column F should be the final answer (F2 = 107.33). The reference table can be formatted differently as well.
At first, I tried using nested-if statements, but realized that I would have like 20+ if statements for all the different outcomes. I think I would want to use the SEARCH function to find weather of not the cell contains a specific piece of information. Then I would probably use some sort of combination of match, if, v-lookup, index, search, but I am not sure how to condense these.
Any suggestion?
SUMPRODUCT is the function you need. I quickly created some test data on the lines of what you shared like this:
Then I entered the below formula in cell F2
=SUMPRODUCT(($I$4:$I$9=E2)*($J$4:$J$9=LEFT(A2,FIND(" ",A2)-1))*IF(ISERROR(FIND("LF",D2,1)),$L$4:$L$9,$K$4:$K$9))
The formula may look a little scary but is indeed very simple as each sub formula checks for a condition that you would want to evaluate. So, for example,
($I$4:$I$9=E2)
is looking for rows that match GRADE of the current row in range $I$4:$I$9 and so on. The * ensures that the arrays thus returned are multiplied and only the value where all conditions are true remains.
Since some of your conditions require looking for partial content like in Species and Machine, I have used Left and Find functions within Sumproduct
This formula simply returns the value from either column K or L based on the matching conditions and you may easily extend it or add more conditions.
I have a question regarding the formula "=COUNTIFS". I have a table with several columns, one is "Project name" and the others are "category 1" and "category2".
The single "=COUNTIF" works fine for me, see below (I am filtering for the word "Preferential" in two columns on the sheet "Entries":
=COUNTIF(Entries!E2:F1099, "Preferential")
The double one "=COUNTIFS" does not work though. Can you please tell me what I do wrong? This is what I am using:
=COUNTIFS(Entries!E2:F1099, "Preferential", Entries!A2:A1099, "Selling GPI")
I always just get the error "#VALUE!".
Thank you very much!
From the documentation found here:
Important: Each additional range must have the same number of rows and columns as the criteria_range1 argument. The ranges do not have to be adjacent to each other.
In your case, the criteria 1 range has 2 columns, while the criteria 2 range has only one.
You can change the formula by :
=COUNTIFS(Entries!E2:E1099, "Preferential", Entries!F2:F1099, "Preferential", Entries!A2:A1099, "Selling GPI")
It should solve your problem. [1]
[1] or maybe not, the second formula implies that "Preferential" should be in both columns E and F
Edit: Corrected formula: If the objective is to count the rows where either E or F are "Preferential" and A is "Selling GPI":
=COUNTIFS(Entries!E2:E1099,"Preferential",Entries!A2:A1099,"Selling GPI")+COUNTIFS(Entries!F2:F1099,"Preferential",Entries!A2:A1099,"Selling GPI")-COUNTIFS(Entries!E2:E1099,"Preferential",Entries!F2:F1099,"Preferential",Entries!A2:A1099,"Selling GPI")
The first COUNTIFS will count rows for columns E and A, the second for F and A, an the third will remove the rows counted twice.
If the objective is to count occurrences of "Preferential" in columns E or F and of "Selling GPI" in column A, you can use:
=COUNTIF(Entries!E2:F1099,"Selling GPI")+COUNTIF(Entries!A2:A1099,"Selling GPI")
I have a question regarding the RANK function in MS Excel 2010. I have a large worksheet whose rows I want to rank based on the values in a column. These values can be positive or negative. I found helpful advice here which explains how to rank the values in a column while excluding all values that equal zero from the ranking and the ranking count. They use the following formula:
IF(O24<0, RANK(O24,$O$24:$O$29) - COUNTIF($O$24:$O$29,0), IF(O24=0, "", RANK(O24,$O$24:$O$29)))
This works great, but it would be even better if I could rank the values only if a corresponding value in the same row but a different column meets certain criteria.
Is something like this possible and how would I do it? How would I update the example formula above to make the change work? Thank you very much in advance for your help.
P.S.: I tried putting in a table but it didn't really work, sorry...
You can use COUNTIFS function to rank based on a condition in another column, e.g. this formula in row 24 copied down [edited to include extra IF)
=IF(O24=0,"",IF(N24="x",COUNTIFS(O$24:O$29,">"&O24,O$24:O$29,"<>0",N$24:N$29,"x")+1,""))
That will rank high to low where column N = "x", ignoring zero values
See this example columns N and O contain random values - press F9 to re-generate new random values and formula results in column Q will change accordingly
It is certainly possible to keep creating more complex formulas whenever you're adding new criteria on which to rank. However by creating intermediary columns with single-step formulas, you'll make your spreadsheet easier to comprehend and easier to add new criteria or edit the existing.
My suggestion is to create a column that excludes the zero's (let's assume this is in column P): =IF(O24 = 0, "", O24)
Then in column R, to eliminate negative values (this step is unnecessary, but your original formula does something similar): =IF(P24 = "", "", P24 - MIN(0, MIN($O$24:$O$29)))
Now in column S, add your newest criteria: =IF(OR(R24="", [enter newest criteria here]), "", R24)
Finally, column T performs the ranking of only the selected rows: =IF(S24="", "", RANK(S24, S$24:S$29))
If exposing columns P, R and S is bothersome, you can always hide them.
A rewording of the answer from barry houdini, using table format.
Value_Col is the column with the values to rank. Group_Column is the column with the group by values, to rank within groups
=COUNTIFS([Value_Col], ">"&[#[Value]], [Value_Column],"<>0", [Group_Column], [#[Group]]) +1