Simple and efficient IFS and SUMIFS - excel-formula

I have a sample attached data and I want to use SUMIFS to evaluate the data
For example, given the following criteria and multiple conditions
Class: buz
Centre: tre
Unit: a
Section: x
I can easily write a sumifs like so :
=SUMIFS(Amount,Class,buz,Centre,tre,Unit,a,Section,x)
However if all values of one or two ranges need to be evaluated and not just one of it like the above, (e.g I want all classes and not just buz) then I can combine if with sumifs
Conditions:
Class: all classes in the table
Centre: tre
Unit: a
Section: x
=If(Class=all classes in a range,
SUMIFS(Amount,Centre,tre,Unit,a,Section,x),
SUMIFS(Amount,Class,buz,Centre,tre,Unit,a,Section,x))
I'm looking for a better way to achieve the above that will be simpler and especially be fast and more efficient as SUMIFS tend to be slow with large datasets.

I think using a * character instead of the class would achieve what you want (return all classes) without changing the formula.
If speed is a concern, VBA can also give you faster solutions, especially if you want to compute this total for a lot of categories.

It is much easier to do this with SUBTOTAL and filters.
Create a cell that has the SUBTOTAL formula
=SUBTOTAL(9,Amount)
and then apply filters to the columns.
Like so:

Related

Rank equally across multiple columns with different data types using a single formula. Is it possible?

See this data set below. It has 3 columns (PTQ, % Growth, $ Growth) that all need ranked individually then summed up and then ranked again for a total power rank of each region. Is there any way I can do this with a single formula? I do this a lot and it would be nice not to have to rank everything individually each time. Basically I need to end up at the "Power Rank" column.
To clarify, I do not want to rank first on one column then another, they all need to be ranked equally together.
Thought I'd add a solution for non-365 users:
Edit: slight amendment so that the returned ranking mimics that of the RANK function, with thanks to #Scott Craner
=MMULT(N(MMULT(CHOOSE({1,2,3},RANK(A2:A10,A2:A10),RANK(B2:B10,B2:B10),RANK(C2:C10,C2:C10)),{1;1;1})>TRANSPOSE(MMULT(CHOOSE({1,2,3},RANK(A2:A10,A2:A10),RANK(B2:B10,B2:B10),RANK(C2:C10,C2:C10)),{1;1;1}))),ROW(A2:A10)^0)+1
which may require committing with CTRL+SHIFT+ENTER, depending on the version of Excel being used.
The static
{1;1;1}
relates to the fact that 3 columns are being queried, and could of course be replaced with a dynamic alternative.
We can use Office 365 LET and SORT. RANK does not allow the use of arrays, so we need to improvise with MATCH and SORT.
=LET(
ptq,A2:A10,
grwt,B2:B10,
grwthd,C2:C10,
ptqrnk,RANK(ptq,ptq),
gwtprnk,RANK(grwt,grwt),
gwtdrnk,RANK(grwthd,grwthd),
sm,ptqrnk+gwtprnk+gwtdrnk,
MATCH(sm,SORT(sm),0))

Summing multiple index match formulas

I am not sure if there is a cleaner way to do this, but I am wondering if it is possible to repeat an index match with multiple different look-up values?
=INDEX(Financials!$B$10:$XFD$10,MATCH('Model'!$G$2,Financials!$B$102:$XFD$102,0))
+INDEX(Financials!$B$10:$XFD$10,MATCH('Model'!$G$3,Financials!$B$102:$XFD$102,0))
+INDEX(Financials!$B$10:$XFD$10,MATCH('Model'!$G$4,Financials!$B$102:$XFD$102,0))
+INDEX(Financials!$B$10:$XFD$10,MATCH('Model'!$G$5,Financials!$B$102:$XFD$102,0))
As you can see, I am doing 4 different index match formulas on the same arrays and only changing the look-up value. Perhaps there is a way to insert an array as the look-up value. Any thoughts welcome! Thanks!
Variations:
Several methods will achieve this, depending on scope/intent (screenshot below refers, here is a shared workbook fyi):
1] =SUMPRODUCT(SUMIFS($B$10:$CB$10,$B$11:$CB$11,$G$2:$G$5))
Courtesy #ScottCraner, this 'does the job'; albeit in the spirit of creating a 'cleaner way', I prefer the following which has greater parsimony / simplicity (i.e. less 'expensive' re time/computation, easier to audit/communicate etc.) & achieves same objective/result:
2a] =SUM(B10:CB10*(G2:G5=$B$11:$CB$11))
Perhaps more intuitive is the following, slight variation to above:
2b] =SUM(IF($B$11:$CB$11=$G$2:$G$5,B10:CB10,""))
You'll struggle with the index function if you wish to sum all values for which there is a much (by the sounds of it, you do, in which case the function would take the form of a filter which would require slightly more complexity in relation to 2, but would on par with 1, assuming the Office 365 pre-requisite for filter is not an issue):
3] =SUM(FILTER(B10:CB10,ISNUMBER(MATCH($B$11:$CB$11,$G$2:$G$5,0))))
Of course, if you really want to reproduce what you have but in a 'cleaner' way, you would deploy the following:
4] =SUM(INDEX($G$13:$CG$13,MATCH(F8:F11,$G$14:$CG$14,0)))
Of course, this abstracts from being able to deal with multiple common values.

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

Excel AGGREGATE Function: #VALUE error when applying boolean array multiplication

For this example I'm starting with this table:
Table example
Now I want to calculate the average for each row relating to its group identifier. For that, the code I have in Column AvgValueOfGroup is
=AGGREGATE(1,6,([#Group]=[Group])*[Value])
This throws a #VALUE error for me.
The last step of the calculation is looking normal:
=AGGREGATE(1,6,{6;0;0;0;0;2})
What am I doing wrong?
P.S.: I'm aware of the alternative solutions around this specific case, but I'll require a solution using aggregate.
The problem is that the aggregate function does not allow array arguments for SUM, AVERAGE, COUNT etc - it always returns #Value. You can only use array arguments with aggregate for things like Large, Small, StDev etc.
It's a bit vague what would be considered the "best", however you could consider adding all these amounts together (subtract the protein) would give you a matrix in which you can get the minimum.
Try:
=INDEX(A2:A5,MATCH(MIN(INDEX(B2:B5+C2:C5+D2:D5-E2:E5+F2:F5,)),INDEX(B2:B5+C2:C5+D2:D5-E2:E5+F2:F5,),0))
Add a multiplication, e.g.: *1.05 to any of the columns if you consider them to be of more importance.

Excel Serial If statements

I'm new to Excel, and I'm struggling with a formula. Essentially, what I'm looking for is to filter a cell through a set of procedures using a formula (this part isn't strict).
For example
Let's say I have a cell, A1. I'm trying to perform different calculations on this based on whether it is between a certain range of values. The problem is, it can be within several ranges.
Pseudo-Code representation
If(A1 > 187.5) {
// Run some code here.
}
If(A1 > 150) {
// Run some code here.
}
NOTE : The above example is only to illustrate the logic of sequential if statements.
Note that I Do not want a nested If statement. I'm just trying to run the same value through various checks. How do I do this in an Excel formula?
The best I can come up with is something like the following.
=(A1>187.5)*<some expression>+(A1>150)*<some expression>+....
The result of this will be some single value. (The straightforward way to get multiple values is to have the individual terms in separate cell.
If you want the result to reflect one among several mutually exclusive outcomes, then you would want to go with:
=(A1>187.5)*<some expression>+(A1>150)*(A1<=187.5)*...etc.
There are many ways to achieve this. One way is to use nested conditions like this:
=IF(Something, do something, IF(something else, do something, do something))
This is good if you want to condensate the formula a bit but arguably leads to more cluttered formulas. According to the FAST-Standard organization, those cases of nested conditions should be replaced by the use of flags. The most simple case would be, for example, where you would be looking for a rebate percentage according to a sales amount. In multiple cells you would have IF conditions evaluating to true only if the value matches that specific range. Then, your formula can be as simple as a SUMPRODUCT of your flags with your rebates percentages.
This is one example, but it can be applied to other cases very well too.
if there is a relationship between the numbers your checking for its very likely you can use
=CHOOSE(FLOOR(A1/160,1)+1,"<160",">160")
Which would put your 150 in the first and leave your 185 in the second

Resources