I have a table with the following header and totals row:
. It has data rows with module names and numbers for the other columns.
I also have this table:
. In the Allocation column each specific segment gets one of: CODE_ZONE, CONST_ZONE or RAM_ZONE.
For each module (row) in SegmentValues I need to make its CODE_ZONE, CONST_ZONE or RAM_ZONE cell the sum of all the segments allocated there, based on the allocation in Segments. I have tried with this formula: =SUMIF(Segments[Allocation], "CODE_ZONE", SegmentValues[#[DIFUNCT]:[SECUID]]), but it only works for the first element. What function should be used in this situation and how?
Try using MMULT function like this:
=MMULT(SegmentValues[#[DIFUNCT]:[SECUID]],(Segments[Allocation]="CODE_ZONE")+0)
MMULT will multiply each value in a single row with the corresponding values in a single column of the same size (and sum the results for a single value). All values need to be numeric so (Segments[Allocation]="CODE_ZONE") returns an array of TRUE/FALSE values and adding 0 converts those to 1/0 values
The SegmentValues range must not contain blanks, but zeroes are OK
I managed to do it using this formula:
=SUMPRODUCT(SegmentValues[#[DIFUNCT]:[SECUID]]*(SegmentValues[[#Headers],[DIFUNCT]:[SECUID]]=Segments[Segments])*(Segments[Allocation]="CODE_ZONE")
It is a SUMPRODUCT with only one array, taken from only one range, but with two conditions:
The header of the cell to be added from SegmentValues matches the segment name in Segments.
The the cell in the Allocation column corresponding to the said Segment cell is CODE_ZONE.
Related
I've got a massive parts spreadsheet that I'm trying to simplify. Various parts could be included in number of locations, which I would like to add up to a single list. The attached file is just an example using reindeer.
This is doable with using a bunch of SUMIF statements added together, but not practical due to the range of columns I need to include. There's gotta be a better way!?
=SUMPRODUCT(--($D$4:$J$11=$A4),$E$4:$K$11))
SUMPRODUCT can do that. Make sure the second range shifts one column, but has equal count of columns (and rows).
($D$4:$J$11=$A4) results in an array of TRUE's or FALSE's for the value in range $D$4:$J$11 being equal to the value in $A4 (no $ prior to it's row number will increase the row # referenced when dragged down).
Adding -- in front of the array converts the TRUE's and FALSE's to 1's and 0's respectively.
Multiplying that with the range to the right of it will result in 1* the value in $E$4:$K$11 for all TRUE's, which results in it's value, or 0* the value in $E$4:$K$11 for all FALSE's, which results in 0.
Summing the array of values results in the sum of all values where the condition is met in the column left from it.
SUMPRODUCT combines the multiplication of the array and summing the array results to 1 total sum.
You can use simply the SUM:
=SUM((D$4:$D$11=A4)*$E$4:$E$11,($F$4:$F$11=A4)*$G$4:$G$11, etc.)
where in etc you can put any range you want. If you don't use 2021/365 version, you must confirm the formula with CTRL+SHIFT+ENTER.
I have a range that I want to sum, which is A2:M35. However, if column 'N' has the number 1 in it, I want to exclude that entire row from the sum. So, If N3 contains 1 I want to exclude the range A3:M3 from the sum calculation. Is this possible?
UPDATE:
I should also include that the 1 or 0 in column N is a flag to state whether this row should be excluded or not (1 = yes, 0 = no). However, this value is derived by checking whether any values in that row = "excluded". So, the additional complication here appears to be that even though the rows with "excluded" in them should be excluded, the sum calculation will show '#VALUE' as it believes some of the values are of the wrong data type (even though they shouldn't be included).
SIMPLE SOLUTION (with helper column)
If you can, to keep it simple, I'd just add a helper column.
So In cell O2:
=IF($N2=1,0,SUM($A2:$M2))
Drag that down to cell O35.
Then you can simply:
=SUM($O$2:$O$35)
COMPLEX SOLUTION (no helper column)
If you would like to avoid having to have a helper column cluttering up your sheet, you could use a SUMPRODUCT formula:
=SUMPRODUCT($A$2:$M$35,(LEN($A$2:$M$35)-LEN($A$2:$M$35))+NOT($N$2:$N$35))
HOW IT WORKS:
The first range (A2:M35) is the array (or in this case a range of excel cells) that you want to sum.
The SUMPRODUCT is going to take each value in that array and multiply it by each corresponding value in the next array we supply, then sum all the results together.
The problem is that the first array is a table, 13 values across and 34 values down. The second array (column N) is only 1 value across. SUMPRODUCT requires that all arrays are the same size.
To do this, we first create an array the correct size:
(LEN(A2:M35)-LEN(A2:M35))
LEN returns an array containing the number of characters in each cell supplied to it. If we take it away from it's self, we are left with an array of the correct size, filled with zeros.
We can then add the values in our smaller array (column N) to the zeros in the array of the correct size, this will fill all the columns with the correct value.
+NOT(N2:N35))
The NOT is there because we want to sum the rows which have a zero. All it is doing is swapping the zeros and ones in column N. So, all 1's become 0's and vice versa.
I hope you can follow my explanation. If not, please let me know and I will elaborate.
I'm trying to create a formula that checks the date column of a row and checks it is within the current month, then checks a separate column in a row and checks it is equal to some text, the formula would then output a count of instances where that is true.
For reference, the columns are named as two ranges, LeadDate and LeadAcquisitionChannel.
[edit] The Refers to: definitions are:
'LeadDate Refers to:
=OFFSET('Enquiry Log'!$A$2,0,0,COUNTA('Enquiry Log'!$A:$A),1) 'LeadAcquisitionChannel Refers to:
=OFFSET('Enquiry Log'!$J$2,0,0,COUNTA('Enquiry Log'!$J:$J),1)
I ran the date check with following formula:
=COUNTIF(LeadDate,">"&EOMONTH(TODAY(),-1)
Which was successful in telling me how many entries fall within the current month.
So I assumed I could then add the multiple criteria in a COUNTIFS like this:
=COUNTIFS(LeadDate,">"&EOMONTH(TODAY(),-1),LeadAcquisitionChannel,B27)
B27 being a cell containing the text I want to check for.
This formula returns me a #VALUE! error.
Any ideas as to why this is happening or whether there is an alternative method I can use?
The key here lies in the Refers to: definitions for both LeadDate and LeadAcquisitionChannel as COUNTIFS requires that each criteria range be the same size and shape of cells.
For a dynamic list of dates that grows when new dates are added:
='Enquiry Log'!$a$2:index('Enquiry Log'!$a:$a, match(1e99, 'Enquiry Log'!$a:$a))
For a matching dynamic list of other information in an adjacent column use the same terminating row like this:
='Enquiry Log'!$j$2:index('Enquiry Log'!$j:$j, match(1e99, 'Enquiry Log'!$a:$a))
Each of these refers to a column of data extending down in each individual column to the row containing the last date in column A.
Your original relied on individual COUNTA counts to reshape OFFSET. There is no guarantee that there isn't an interim blank row or that they each continue down to the same row. You could homogenize the originals with,
=OFFSET('Enquiry Log'!$J$2, 0, 0, COUNTA('Enquiry Log'!$A:$A), 1)
... but that still doesn't guarantee that interim blank cells in column A wouldn't skew results.
I am not into Excel and I have this problem trying to sum the values of 2 different column and put this result value into a cell.
So basically I have the D column containing 2 values (at the moment only 2 but will grows without a specific limit, I have to sum all the values in this column). These value are decimal values (in my example are: 0,3136322400 and 0,1000000000).
Then I have an I column containing the same type of value (at the moment only one but also the values in this column can grow without a specific limit...in my example at this time I have this value −0,335305)
Then I have the K3 cell where I have to put the sum of all the valus into the D column and all the values into the I column (following my example it will contain the result of this sum: 0,3136322400 + 0,1000000000 −0,335305.
Following a tutorial I tried to set this simple forumla in the K3 cell:
=SUM(A:I)
The problem is that in this cell now I am not obtaining the expected result (that is 0.07832724) but I am obtaining this value: 129236,1636322400.
It is very strange...I think that maybe it can depend by the fact that the D and the I column doesn't contain only number but both have a textual "heder" (that is the string "QUANTITY" for both the cells). So I think that maybe it is adding also the number conversion of this string (but I am absolutly not sure about this assertion).
So how can I handle this type of situation?
Can I do one of these 2 things:
1) Adding the column values starting from a specific starting cell in the column (for example: sum all the values under a cell without specify a down limit).
2) Exclude in some way the "header" cells from my sum so the textual values are not considered in my sum.
What could be a smart solution for my problem? How can I fix this issue?
The sum function can take several arguments.
=sum(d2:d10000, i2:I10,000, more columns )
This should remove the header from the calculation.
If you turn your data into an Excel Table (Insert > Table), you can use structured referencing to address a table column, excluding the header.
=SUM(Table1[This Header],Table1[That Header])
Then you don't need to reference whole columns. If you add new data to the table, the formula will take that into account.
I'm trying to use the approximate match function of vlookup to find a value in an array, that can be of different length. I just dragged the lookup array as far down as possible in order to assure that all data is selected, however, the approximate match option will then always select the last value in the array. Is there a way of feeding vlookup the correct lookup array in order to extract the correct value? Regards
Create a dynamic range name and feed that into the Vlookup. For example, if your lookup table starts in A1 and has numeric data, define a name called TheRange with the formula
=Sheet1!$A$1:Index(Sheet1!$D:$D,match(99^99,Sheet1!$A:$A,1))
This will return a range from A1 to column D down to the last row with a number in column A. When rows are added or removed from the table, the named range will be recalculated automatically and adjust to the new dimensions.
Then can use
=vlookup(YourValue,TheRange,2,1)
Adjust cell addresses to your situation. I take it you are aware that for an approximate match the data must be sorted ascending for the formula to return the correct result. With the 1 or TRUE as the last parameter, the formula will always return a result, but if the table is not sorted on the first column, the result is most likely not correct.