How do I sum results of two if statements in the same cell? - excel

I'm looking to have the results of two If statements calculated and added in the same cell. I'm getting #VALUE! error.
=IF(ISERROR(GETPIVOTDATA("Sum of CHARGES",'Ship City'!$A$3,"ship_city",$B$7,"carrier_type",$A$27,"INV_month_id",D$6,"INV_year_id",$D$5,"Company Name",$B29)),"",GETPIVOTDATA("Sum of CHARGES",'Ship City'!$A$3,"ship_city",$B$7,"carrier_type",$A$27,"INV_month_id",D$6,"INV_year_id",$D$5,"Company Name",$B29))+IF(ISERROR(GETPIVOTDATA("Sum of CHARGES",'Recipient City'!$A$4,"recipient_city",$B$7,"carrier_type",$A$27,"INV_month_id",D$6,"INV_year_id",$D$5,"Company Name",$B29)),"",GETPIVOTDATA("Sum of CHARGES",'Recipient City'!$A$4,"recipient_city",$B$7,"carrier_type",$A$27,"INV_month_id",D$6,"INV_year_id",$D$5,"Company Name",$B29))
=IF(ISERROR(GETPIVOTDATA("Sum of CHARGES",'Ship City'!$A$3,"ship_city",$B$7,"carrier_type",$A$27,"INV_month_id",D$6,"INV_year_id",$D$5,"Company Name",$B29)),"",GETPIVOTDATA("Sum of CHARGES",'Ship City'!$A$3,"ship_city",$B$7,"carrier_type",$A$27,"INV_month_id",D$6,"INV_year_id",$D$5,"Company Name",$B29))
+
IF(ISERROR(GETPIVOTDATA("Sum of CHARGES",'Recipient City'!$A$4,"recipient_city",$B$7,"carrier_type",$A$27,"INV_month_id",D$6,"INV_year_id",$D$5,"Company Name",$B29)),"",GETPIVOTDATA("Sum of CHARGES",'Recipient City'!$A$4,"recipient_city",$B$7,"carrier_type",$A$27,"INV_month_id",D$6,"INV_year_id",$D$5,"Company Name",$B29))

Your both IF functions return an empty string "". Using + operator with strings returns #VALUE!. There are different methods to fix it:
use 0 instead of ""
use SUM instead of + (it ignores strings).
And as #John Bustos mentioned in his comment, you can simplify your formula with
IFERROR(value,value_if_error)
IFERROR description

Related

Why am I getting a value error in excel while using the ifs function?

=IFS(SEARCH("C*",A9),"Cake",SEARCH("K*",A9),"Cookies",SEARCH("B*",A9),"Bread & Bun",SEARCH("Y*",A9),"Pastry")
It works for the first criteria and returns "cake" but won't work for the others. I keep getting a #VALUE error.
Can help please??
SEARCH isn't a Boolean-valued function. It doesn't return FALSE if the string isn't found -- it returns a #VALUE! error which isn't coerced to FALSE.
What you could do is wrap everything like SEARCH("C*",A9) with ISNUMBER(): ISNUMBER(SEARCH("C*",A9)) since Excel can tell that #VALUE! isn't a number.

nested ifs with multiple sumifs based on changing criteria

I am having trouble with this formula and would like to know if I am even building it in the correct order or how i can change it to get the desired result. Getting formula missing an opening or closing parenthesis error:
=IF(BH2="PPD TO FSC",SUMIFS('ALL BIDS'!R:R,'ALL BIDS'!D:D,BV2,'ALL BIDS'!E:E,I2,'ALL BIDS'!W:W,'DC TOOL'!U2,'ALL BIDS'!G:G,'DC TOOL'!V2,'ALL BIDS'!H:H,'DC TOOL'!M2),SUMIFS(FREIGHT!Z:Z,FREIGHT!Q:Q,'DC TOOL'!F2,FREIGHT!M:M,H2,FREIGHT!O:O,"PPD",FREIGHT!AA:AA,GRIDS!$U$3),IF(BH2="PPD TO GDC",SUMIFS('ALL BIDS'!R:R,'ALL BIDS'!D:D,F2,'ALL BIDS'!E:E,I2,'ALL BIDS'!W:W,'DC TOOL'!U2,'ALL BIDS'!G:G,'DC TOOL'!V2,'ALL BIDS'!H:H,'DC TOOL'!M2),SUMIFS(FREIGHT!Z:Z,FREIGHT!Q:Q,'DC TOOL'!F2,FREIGHT!M:M,H2,FREIGHT!O:O,"PPD",FREIGHT!AA:AA,GRIDS!$U$3))
Looks like you want 3 different possible SUMIFS, with the logic being as follows:
IF BH2 = "x" SUMIFS1, IF BH2 = "y" SUMIFS2 else SUMIFS3 so you need to write that like this:
=IF(BH2="PPD TO FSC",SUMIFS('ALL BIDS'!R:R,'ALL BIDS'!D:D,BV2,'ALL BIDS'!E:E,I2,'ALL BIDS'!W:W,'DC TOOL'!U2,'ALL BIDS'!G:G,'DC TOOL'!V2,'ALL BIDS'!H:H,'DC TOOL'!M2),IF(BH2="PPD TO GDC",SUMIFS('ALL BIDS'!R:R,'ALL BIDS'!D:D,F2,'ALL BIDS'!E:E,I2,'ALL BIDS'!W:W,'DC TOOL'!U2,'ALL BIDS'!G:G,'DC TOOL'!V2,'ALL BIDS'!H:H,'DC TOOL'!M2),SUMIFS(FREIGHT!Z:Z,FREIGHT!Q:Q,'DC TOOL'!F2,FREIGHT!M:M,H2,FREIGHT!O:O,"PPD",FREIGHT!AA:AA,GRIDS!$U$3)))

WorksheetFunction.value() missing in Excel

In a spreadsheet formula, =VALUE("$100") will evaluate to the numeric value of 100. I then tried to access this function in VBA via WorksheetFunction object, however it is missing.
In VBA I tried the conversion function Val("$100"), however that returns 0. So how can I accomplish this via VBA?
Val() only really works if the string is all numbers I'm afraid - currency signs cause it a problem.
If you're always going to have the same currency sign in the string, it might be worth using something like
StringName = replace(StringName, "$", "")
to take out the $ by replacing it with "" - otherwise if your strings aren't always going to be this predictable the below question might help:
How to find numbers from a string?
see https://learn.microsoft.com/en-us/office/vba/api/excel.worksheetfunction.numbervalue
example of using above, which will return a value of -1234.56:
MsgBox WorksheetFunction.NumberValue("-$1,234.56", ".", ",")
Note that if the result is non-numeric, it throws an error. For example (swapping the comma grouping and decimal character params which is invalid in this case):
MsgBox WorksheetFunction.NumberValue("-$1,234.56", ".", ",")
I don't understand why the above link doesn't have any version info. It is currently dated 2019‎-‎05‎-‎23 - no idea if that's because it is new or if it was recently updated.

How can I nest an vector index match function in an if statement? (Excel)

I have the following vector function:
{=INDEX(Key!$K$2:$K$25,MATCH(TRUE,ISNUMBER(SEARCH(Key!$K$2:$K$25,V5)),0))}
This function returns what is in Key!$K$2:$K$25 if V5 is a match. This formula works. I would like to also make the function return, "Not Found", if the value searched for is not present in Key!$K$2:$K$25. I have tried the following, but it doesn't work. Could someone help?
{=IF(MATCH(TRUE,ISNUMBER(SEARCH(Key!$K$2:$K$25,V3)),0),INDEX(Key!$K$2:$K$25,MATCH(TRUE,ISNUMBER(SEARCH(Key!$K$2:$K$25,V3)),0)),"Not Found")}
Thanks.
simply merge your =INDEX(Key!$K$2:$K$25,MATCH(TRUE,ISNUMBER(SEARCH(Key!$K$2:$K$25,V5)),0)) with IFERROR
=IFERROR(INDEX(Key!$K$2:$K$25,MATCH(TRUE,ISNUMBER(SEARCH(Key!$K$2:$K$25,V5)),0)),"Not found")

Cognos query calculation - how to obtain a null/blank value?

I have a query calculation that should throw me either a value (if conditions are met) or a blank/null value.
The code is in the following form:
if([attribute] > 3)
then ('value')
else ('')
At the moment the only way I could find to obtain the result is the use of '' (i.e. an empty character string), but this a value as well, so when I subsequently count the number of distinct values in another query I struggle to get the correct number (the empty string should be removed from the count, if found).
I can get the result with the following code:
if (attribute='') in ([first_query].[attribute]))
then (count(distinct(attribute)-1)
else (count(distinct(attribute))
How to avoid the double calculation in all later queries involving the count of attribute?
I use this Cognos function:
nullif(1, 1)
I found out that this can be managed using the case when function:
case
when ([attribute] > 3)
then ('value')
end
The difference is that case when doesn't need to have all the possible options for Handling data, and if it founds a case that is not in the list it just returns a blank cell.
Perfect for what I needed (and not as well documented on the web as the opposite case, i.e. dealing with null cases that should be zero).

Resources