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)
Related
I want to find which user is "P" given a date in data below.
I've tried retrieving the row number of the given date using "=MATCH(A5,$A$4:$A$5,0)"
and also the column number of "P", using "=MATCH("P",B5:G5,0)"
I'm unsure how to bring them together to get the desired output.
Thanks for any help.
Nested INDEX/MATCH
=IFNA(INDEX($B$1:$G$1,1,MATCH($J2,INDEX($B$2:$G$3,MATCH($I2,$A$2:$A$3,0),0),0)),"")
Insert a new column H where H4 has a formula of =INDEX(B$3:G$3,MATCH("P",B4:G4,0).
Then your second table's second column formula can be =INDEX(H$4:H$5, MATCH(yourDateCellHere, A$4:A$5,0)) because a lot of the heavy lifting is already done in the first table.
Then, if you wish, hide your new column H.
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
I am trying to do a summation of rows with certain dynamic conditions. I have rows like:
A can be only one value, K can have multiple OR-values. In the end M is to be summed.
I have tried to use SUMPRODUCT() which works for column A but not for K. What I am looking for is something like:
=SUMPRODUCT(--(!$A$2:$A$20000="AA")*--(!$K$2:$K$20000="AA" OR "BB")*$M$2:$M$20000)
I know I can do ="AA" and then ="BB" but I need "AA" and "BB" to be dynamic based on other cells. And the number of arguments is different. I tried {"AA";"BB"} but I know this will not work as the match then needs to be in the same row.
Can it at all be achieved?
Thanks a lot!
=SUMPRODUCT(($A$2:$A$20000="AA")*(($K$2:$K$20000="AA")+($K$2:$K$20000="BB"))*$M$2:$M$20000)
Note that:
Since you are multiplying/adding arrays, there's no need to include the double unary's
I don't know why you have a ! in your example formula.
To return an OR array of TRUE;FALSE, we add.
Your comments still do not provide a clear explanation of what you are making dynamic.
But to create a dynamic OR for column K, including testing for column A and summing column M, you can do the following:
For column K, let us assume that your possible OR's are entered separately in the range F2:F10
=SUMPRODUCT(MMULT(--($K$2:$K$20000=TRANSPOSE($F$2:$F$10)),--(ROW($F$2:$F$10)>0))*($A$2:$A$20000="AAA")*$M$2:$M$20000)
The matrix multiplication will produce a single column of 19,999 entries which will be a 1 for matches of any of the OR's and 0 if it does not match.
See How to do a row-wise sum in an array formula in Excel?
for information about the MMULT function in this application.
In the above formula, "blanks" in the OR range (F2:F10) will also match blank entries in column K. So it is conceivable that if there is a blank in K and F and a AAA in col A and a value in column M that a wrong result might be returned.
To avoid that possibility, we can use a dynamic formula to size column F where we are entering our OR values:
=INDEX($F$2:$F$10,1):INDEX($F$2:$F$10,COUNTA($F$2:$F$10))
will return only the values in col F that are not blank (assuming no blanks within the column)
So:
=SUMPRODUCT(MMULT(--($K$2:$K$20000=TRANSPOSE(INDEX($F$2:$F$10,1):INDEX($F$2:$F$10,COUNTA($F$2:$F$10)))),--(ROW(INDEX($F$2:$F$10,1):INDEX($F$2:$F$10,COUNTA($F$2:$F$10)))>0))*($A$2:$A$20000="AAA")*$M$2:$M$20000)
Given this data:
the last formula will return a value of 5 (sum of M2,M3,M7)
Use SUMIFS with SUMPRODUCT wrapper:
=SUMPRODUCT(SUMIFS($M$2:$M$20000,$A$2:$A$20000,"AA",$K$2:$K$20000,{"AA","BB"}))
I want to count number of values (N/D) in the array (below:table: list) for criteria 1 is date range( from date and through Date) and criteria 2 is Shift A, b acros ( as shown in below table-output). I want to fill column D/N with how many times D/N occur for a date range and shift A,B,C,D?
output
From Date Through Date Shift D/N
25-May-19 26-May-19 A ?
25-May-19 26-May-19 B ?
Table- list
Dates A B C D
25-May-19 N D - -
26-May-19 N D - -
27-May-19 - D N -
INDEX(A:E,MATCH(H7:I7,A:E,0),MATCH(J7,A:E,0))
Value -?
Part of the problem you may be having is dates. Make sure your dates are excel dates and not string/text that looks like a date. Simply changing the formatting of a cell does not make it a date, it simply tells excel how to try and display the information in a cell.
Dates in excel are stored as integers and they represent the days since 1900/1/1 with that date being day 1. One of the easiest ways to test if a cell contains a date or a string is:
=ISTEXT(A1)
or
=ISNUMBER(A1)
Where A1 is the cell with the date to be tested.
If it returns TRUE for the first formula it is a string/text. FALSE means it is a number. The opposite TRUE and FALSE results apply for the second formula.
In your formula's when you have something between quotes "", it will be interpreted as a string. SO something like "<=19/05/26" mean its looking for a string less than that, not a date less than that. For doing a date comparison, either concatenate the text comparison with with a cell containing a date to compare to "<="&B2 where B2 has the date or if you want to hard code it use something like "<="&Date(19,05,26)
In order to make the following solution work, your dates all need to be stored as a number. AKA Excel serial date format.
Based on the data being layed out as per the image below, you can use COUNTIFS, INDEX, and MATCH to get the date your are looking for. I recommend find your count of D and N separately and adding them together after for a total. However if you want it in a single cell formula solution it can be achieved as well as demonstrated by the results in column N. however the formula starts to get long and can be difficult potentially read/maintain at a later date.
The core of the solution will be the COUNTIFS functions. The format of the COUNTIFS function is as follows:
COUNTIFS(Range to count 1, Criteria 1, Range to count 2, Criteria 2,...,Range to count n, Criteria n)
Let start building your formula one criteria at a time. The first Criteria will be all dates that are greater than or equal to the from date. If you only want the dates after the from date, drop the equal sign or the criteria.
=COUNTIFS($A$2:$A$4,">="&$G2,
Note the $ to lock the cell references. This is done so that when the formula gets copied, the column or row references beside the $ does not change.
Then second criteria is similar to the first except you want to grab all the dates less than or equal to the through date. Again include/drop the equal sign to suit your needs.
=COUNTIFS($A$2:$A$4,">="&$G2,$A$2:$A$4,"<="&$H2,
The next criteria will be to get all the cells that match D or N the column header. Lets just focus on D for now. The tricky part is to define which column to look in. For now lets call the column to look in XXX which will make the formula become:
=COUNTIFS($A$2:$A$4,">="&$G2,$A$2:$A$4,"<="&$H2,XXX,J$1)
OR
=COUNTIFS($A$2:$A$4,">="&$G2,$A$2:$A$4,"<="&$H2,XXX,"="&J$1)
NOTE: both formulas are the same. When no comparison operator is provided
it is taken as "=" by default.
Now in order to define XXX, INDEX and MATCH will be your friends. An important side note about INDEX is that it does not directly return the value of a cell but instead returns a cell address which in turn pulls a cell value. The basic format of INDEX is:
INDEX(Range to look in, Range's ROW to look in, Range's COLUMN to look in)
That is for a 2 dimensional range. If your range is 1 dimensional, either just a column or just a row, then only the second argument "Range's Row..." need to be provided and it represents how far down the list to go.
What gets interesting about a 2D INDEX is that when 0 is provided for ROW to look in or the Column to look in, instead of throwing an error, it instead returns all rows or columns. THIS IS IMPORTANT because you want all rows of just 1 specific column. That mean your INDEX formula is going to start to look like:
INDEX($B$2:$E$4,0,SPECIFIC COLUMN NUMBER)
So now you need to find a specific column number. That is where MATCH will be your friend. MATCH takes the following format:
MATCH(Value to find, 1D range to look in, what type of search)
You already know you are going to try and match your shift column so that will be your look up value, and the range to look in will be your column headers. The type of search you will want in this case is an exact match which is represented by 0. That means your MATCH formula will look like:
MATCH($I2,$B$1:$E$1,0)
Now to combine the various pieces, throw the MATCH formula into your INDEX and replace the "SPECIFIC COLUMN...". Your INDEX will now look like:
INDEX($B$2:$E$4,0,MATCH($I2,$B$1:$E$1,0))
And the formula above can now replace the XXX in your COUNTIFS formula and you will get:
=COUNTIFS($A$2:$A$4,">="&$G2,$A$2:$A$4,"<="&$H2,INDEX($B$2:$E$4,0,MATCH($I2,$B$1:$E$1,0)),J$1)
Place the above formula in J2 and copy the cell down and to the right.
In L2 use one of the two formulas to get the total of D and N in the date range:
=SUM(J2:K2)
OR
=J2+K2
Now to get your formula all in one cell, look at the second formula above. You can simply go to the contents of cell J2 and copy the entire formula. Then edit cell L2 and replace the cell reference for for J2 with the copied formula. Repeat the process by copy formula in K2 and replacing the reference to K2 in L2. You will wind up with a formula that looks like:
=COUNTIFS($A$2:$A$4,">="&$G2,$A$2:$A$4,"<="&$H2,INDEX($B$2:$E$4,0,MATCH($I2,$B$1:$E$1,0)),J$1)+COUNTIFS($A$2:$A$4,">="&$G2,$A$2:$A$4,"<="&$H2,INDEX($B$2:$E$4,0,MATCH($I2,$B$1:$E$1,0)),K$1)
Much longer and harder to read which is why I recommend breaking the formula down into its parts for D and N separately.
Now as an alternate method you could use SUMPRODUCT and get into array operations. Your SUMPRODUCT formula to place in I2 and copy down and right could be:
=SUMPRODUCT(($A$2:$A$4>=$G2)*($A$2:$A$4<=$H2)*(INDEX($B$2:$E$4,0,MATCH($I2,$B$1:$E$1,0))=J$1))
In the following formula I sum up values in a column, I like to expand this so that it discounts values, if a value in another column ends with a "*D".
So far I have got it so that it sum only those that end in a "*D".
=SUMPRODUCT(SUBTOTAL(9,OFFSET($DY$16,ROW($DY$16:$DY$273)-ROW($DY$16),,1)),--ISNUMBER(SEARCH("*D",$EB$16:$EB$273)))
Question 1: How to reverse the formula to exclude value "*D"?
The --ISNUMBER part of your formula evaluates TRUE whenever the "D" is located
Changing this part to -ISERROR will evaluate TRUE whenever the "D" is not located
=SUMPRODUCT((IFERROR(SEARCH("D",CategoryRange),"-")<>LEN(CategoryRange))*SumRange)
should work if there is only on D.
CategoryRange is the range of cells in Category code column and SumRange is the range of cells in column to be summed over
It works for me. IFERROR(SEARCH("D",CategoryRange),"-") finds the position of 'D' in the Categore Code column, if it is not equal to LEN(CategoryRange) then the 'D' is not at the end, which creates a boolean array that you want. Please check it stepwise with "Evaluate Formula" in excel.