Excel - SUMIFS: changing sign of summed elements based on criteria - excel

I need to implement the following formula to get the desired result ($32.000 instead of $96.000) - as from cell C3 (see picture)
=IF(ISNUMBER(SEARCH("Assets",INDEX(F:F,MATCH(B3,G:G,0)))),1,-1)*SUMIFS(H:H,G:G,B3)
The issue is that the formula sets the sign (+ or -) for the whole formula based on the first parameter it founds ("+" for "Assets" ; "-" for "Liabilities") when it should treat them independently and sum them accordingly.
I've managed to get the result using the "Account"'s parameters (besides the "Ledger Account"'s) as external criteria, but that's something I'd like to avoid.
=SUMIFS($G:$G;$F:$F;B3;$E:$E;E3)-SUMIFS($G:$G;$F:$F;B3;$E:$E;E4)

I think you've got something that works with that second formula. Stringing together a few sumifs is a simple way of solving this:
=SUMIFS(G:G,F:F,B3,E:E,"*assets")+SUMIFS(G:G,F:F,B3,E:E,"*revenues")-SUMIFS(G:G,F:F,B3,E:E,"*liabilities")-SUMIFS(G:G,F:F,B3,E:E,"*costs")

Related

V-Lookup across multiple arrays

I am having trouble using lookup functions to achieve the following.
From Table-1, I need to look-up the Items list, and depending on what type of item it is (Fruit/Veg/Seed), pull in the corresponding percentage to Table-2. I have tried to so this using Vlookup and nested IFs but its not working.
=IF((VLOOKUP($A$10:$A$16,$A$1:$E$8,2,FALSE)=$B$9),$C$1:$C$8,IF((VLOOKUP($A$10:$A$16,$A$1:$E$8,4,FALSE)= $E$1:$E$8,""))
You need to do two VLOOKUP's. The first for Cat-1, and the second for Cat-2:
=IF(VLOOKUP($B13,$B$4:$F$10,2,FALSE)=C$12,VLOOKUP($B13,$B$4:$F$10,3,FALSE),
IF(VLOOKUP($B13,$B$4:$F$10,4,FALSE)=C$12,VLOOKUP($B13,$B$4:$F$10,5,FALSE),""))
Enter in C13 and fill across and down.
The second VLOOKUP is entered into the value_if_false portion of the first IF.

Excel - Array Formula Extend

I am using this array formula which works fine
=IF(ROWS(K$62:K62)>COUNTIF(accounts_table[§],"<>J"),"",INDEX(accounts_table[Account Name],SMALL(IF(accounts_table[§]<>"J",ROW(accounts_table[§])-ROW(Ledger!$H$17)+1),ROWS($K$62:K62))))
However, I need to extend this for multiple COUNTIF Criteria:
accounts_table[§],"<>J"
accounts_table[§],"<>T"
accounts_table[§],"<>P"
I haven't been successful in doing this. I have tried this but doesn't work:
=IF(OR(ROWS(K$62:K62)>COUNTIF(accounts_table[§],"<>J"),ROWS(K$62:K62)>COUNTIF(accounts_table[§],"<>T")),"",INDEX(accounts_table[Account Name],SMALL(IF(OR(accounts_table[§]<>"J",accounts_table[§]<>"T"),ROW(accounts_table[§])-ROW(Ledger!$H$17)+1),ROWS($K$62:K62))))
You have to make two adjustments to the formula:
(1) I was talking total rubbish previously, it is correct that the easiest thing to do is to use Countifs. You could subtract the two separate counts of J and T from the total, but it's longer.
(2) You can't use AND or OR in array formulas - they only give you one result for the entire array instead of iterating over the cells like you want them to. Instead you have to use multiply (*) or add (+). Here you are trying to include cells which are both not equal to J and not equal to T, so again you need AND logic, therefore you want to multiply.
=IF(ROWS(K$62:K62)>COUNTIFS(accounts_table[§],"<>J",accounts_table[§],"<>T"),"",INDEX(accounts_table[Account Name],SMALL(IF((accounts_table[§]<>"J")*(accounts_table[§]<>"T"),ROW(accounts_table[§])-ROW(Ledger!$H$2)+1),ROWS(K$62:$K62))))
Extending it to more variables is left as an exercise for the reader...unless you have a real lot of values to exclude in which case another approach might be needed.

IF Excel function - Wildcard alternative in 'logical_test' segment

I'm struggling to include a wildcard at an IF function. I am aware that the IF function does not support a Wildcard. I've seen a few posts on SO, which I can't understand why they aren't working with my formula.
Here is my original formula (which works):
{=SUM(--(FREQUENCY(IF(SHEET1!D1:D10="Text", SHEET1!D1:D10), SHEET1!D1:D10)>0))}
Here is what I'd like to do:
{=SUM(--(FREQUENCY(IF(SHEET1!D1:D10="*"&A1&"*", SHEET1!D1:D10), SHEET1!D1:D10)>0))}
This would allow me to just modify whatever text is in A1 to get the result that I want in the adjacent cell containing the formula.
I've tried replacing the IF's logical_test with FIND(), IFERROR(), SEARCH(), as well as multiple other functions and combinations that I have gathered from other posts, but I fail at getting the result that I want.
Looking forward to receiving some support.
SHEET1
SHEET2

Using SUMIFS with multiple AND OR conditions

I would like to create a succinct Excel formula that SUMS a column based on a set of AND conditions, plus a set of OR conditions.
My Excel table contains the following data and I used defined names for the columns.
Quote_Value (Worksheet!$A:$A) holds an accounting value.
Days_To_Close (Worksheet!$B:$B) contains a formula that results in a number.
Salesman (Worksheet!$C:$C) contains text and is a name.
Quote_Month (Worksheet!$D:$D) contains a formula (=TEXT(Worksheet!$E:$E,"mmm-yy"))to convert a date/time number from another column into a text based month reference.
I want to SUM Quote_Value if Salesman equals JBloggs and Days_To_Close is equal to or less than 90 and Quote_Month is equal to one of the following (Oct-13, Nov-13, or Dec-13).
At the moment, I've got this to work but it includes a lot of repetition, which I don't think I need.
=SUM(SUMIFS(Quote_Value,Salesman,"=JBloggs",Days_To_Close,"<=90",Quote_Month,"=Oct-13")+SUMIFS(Quote_Value,Salesman,"=JBloggs",Days_To_Close,"<=90",Quote_Month,"=Nov-13")+SUMIFS(Quote_Value,Salesman,"=JBloggs",Days_To_Close,"<=90",Quote_Month,"=Dec-13"))
What I'd like to do is something more like the following but I can't work out the correct syntax:
=SUMIFS(Quote_Value,Salesman,"=JBloggs",Days_To_Close,"<=90",Quote_Month,OR(Quote_Month="Oct-13",Quote_Month="Nov-13",Quote_Month="Dec-13"))
That formula doesn't error, it just returns a 0 value. Yet if I manually examine the data, that's not correct. I even tried using TRIM(Quote_Month) to make sure that spaces hadn't crept into the data but the fact that my extended SUM formula works indicates that the data is OK and that it's a syntax issue. Can anybody steer me in the right direction?
You can use SUMIFS like this
=SUM(SUMIFS(Quote_Value,Salesman,"JBloggs",Days_To_Close,"<=90",Quote_Month,{"Oct-13","Nov-13","Dec-13"}))
The SUMIFS function will return an "array" of 3 values (one total each for "Oct-13", "Nov-13" and "Dec-13"), so you need SUM to sum that array and give you the final result.
Be careful with this syntax, you can only have at most two criteria within the formula with "OR" conditions...and if there are two then in one you must separate the criteria with commas, in the other with semi-colons.
If you need more you might use SUMPRODUCT with MATCH, e.g. in your case
=SUMPRODUCT(Quote_Value,(Salesman="JBloggs")*(Days_To_Close<=90)*ISNUMBER(MATCH(Quote_Month,{"Oct-13","Nov-13","Dec-13"},0)))
In that version you can add any number of "OR" criteria using ISNUMBER/MATCH
You can use DSUM, which will be more flexible. Like if you want to change the name of Salesman or the Quote Month, you need not change the formula, but only some criteria cells. Please see the link below for details...Even the criteria can be formula to copied from other sheets
http://office.microsoft.com/en-us/excel-help/dsum-function-HP010342460.aspx?CTT=1
You might consider referencing the actual date/time in the source column for Quote_Month, then you could transform your OR into a couple of ANDs, something like (assuing the date's in something I've chosen to call Quote_Date)
=SUMIFS(Quote_Value,"<=90",Quote_Date,">="&DATE(2013,11,1),Quote_Date,"<="&DATE(2013,12,31),Salesman,"=JBloggs",Days_To_Close)
(I moved the interesting conditions to the front).
This approach works here because that "OR" condition is actually specifying a date range - it might not work in other cases.
Quote_Month (Worksheet!$D:$D) contains a formula (=TEXT(Worksheet!$E:$E,"mmm-yy"))to convert a date/time number from another column into a text based month reference.
You can use OR by adding + in Sumproduct. See this
=SUMPRODUCT((Quote_Value)*(Salesman="JBloggs")*(Days_To_Close<=90)*((Quote_Month="Cond1")+(Quote_Month="Cond2")+(Quote_Month="Cond3")))
ScreenShot
Speed
SUMPRODUCT is faster than SUM arrays, i.e. having {} arrays in the SUM function. SUMIFS is 30% faster than SUMPRODUCT.
{SUM(SUMIFS({}))} vs SUMPRODUCT(SUMIFS({})) both works fine, but SUMPRODUCT feels a bit easier to write without the CTRL-SHIFT-ENTER to create the {}.
Preference
I personally prefer writing SUMPRODUCT(--(ISNUMBER(MATCH(...)))) over SUMPRODUCT(SUMIFS({})) for multiple criteria.
However, if you have a drop-down menu where you want to select specific characteristics or all, SUMPRODUCT(SUMIFS()), is the only way to go. (as for selecting "all", the value should enter in "<>" + "Whatever word you want as long as it's not part of the specific characteristics".
In order to get the formula to work place the cursor inside the formula and press ctr+shift+enter and then it will work!
With the following, it is easy to link the Cell address...
=SUM(SUMIFS(FAGLL03!$I$4:$I$1048576,FAGLL03!$A$4:$A$1048576,">="&INDIRECT("A"&ROW()),FAGLL03!$A$4:$A$1048576,"<="&INDIRECT("B"&ROW()),FAGLL03!$Q$4:$Q$1048576,E$2))
Can use address / substitute / Column functions as required to use Cell addresses in full DYNAMIC.

simplifying Excel formula currently using INDEX, ROW, SUMPRODUCT and IFERROR

Does anyone have any brilliant ideas to simplify this difficult formula? Don't panic when you see it, I will try to explain.
=IFERROR(INDEX(rangeOfDesiredValues,(1/SUMPRODUCT((rangeOfSerials=$D20)(rangeOfApps=cfgAppID)(rangeOfAccessIDs=cfgAccessID)*ROW(rangeOfDesiredValues))^-1)),"")
Currently I am using SUMPRODUCT to do the equivalent of a VLOOKUP with multiple columns as criteria. Usually that only works with number results, but since I need to find text, I'm using SUMPRODUCT in combination with ROW and INDEX.
Unfortunately when no cell is found, my SUMPRODUCT returns 0. This causes the formula to return the incorrect cell rather than blank. For this reason I am running the result through this calculation:
(1 / result)^-1
This way results of 0 become an error, and other results remain unchanged. I feed this into IFERROR, so that errors become blanks.
Does anyone know how to make this neater? I am not able to create new columns in any of my spreadsheets.
It's always best to avoid using multi-condition summing functions like SUMPRODUCT when you want to find a single value (it would obviously give you an incorrect result or error if there's more than one row which matches all three conditions, I assume you expect one match at most here?). ROW function can also be problematic if you insert any rows in the worksheet.....
There are several approaches that can work. For a single formula, using MATCH is the most common - MATCH will only give the correct position or an error so no problems with zero values. That would look like this:
=IFERROR(INDEX(rangeOfDesiredValues,MATCH(1,(rangeOfSerials=$D20)*(rangeOfApps=cfgAppID)*(rangeOfAccessIDs=cfgAccessID),0)),"")
That's an "array formula" that needs to be entered with CTRL+SHIFT+ENTER......or you can make it into a regular formula with an extra INDEX function like this
=IFERROR(INDEX(rangeOfDesiredValues,MATCH(1,INDEX((rangeOfSerials=$D20)*(rangeOfApps=cfgAppID)*(rangeOfAccessIDs=cfgAccessID),0),0)),"")
A third alternative is to use LOOKUP which doesn't need "array entry"
=IFERROR(LOOKUP(2,1/(rangeOfSerials=$D20)/(rangeOfApps=cfgAppID)/(rangeOfAccessIDs=cfgAccessID),rangeOfDesiredValues),"")
That differs slightly from the previous versions in the case of multiple matches - it will give you the last match rather than the first in that scenario (but I assume you have only one match at most, as stated above).
Finally, if you don't mind using helper columns you could simplify the formulas considerably. Just use a "helper" column to concatenate the three criteria columns separated by dashes and then you can use a simple VLOOKUP or INDEX/MATCH, e.g.
=IFERROR(INDEX(rangeOfDesiredValues,MATCH($D20&"-"&cfgAppID&"-"&cfgAccessID,Helper_Column,0)),"")

Resources