How to convert this condition to an excel function ..? - excel

Please, I need to write this condition in excel as a function :
if( A1 = 2 AND A2= 3 ) then { A3 will equal 10}
else if( A1 = 4 AND A2= 5 ) then { A3 will equal 20}
else if ( A1 = 6 AND A2= 7 ) then { A3 will equal 30}
A1, A2, A3 are the excel cells
thanks a lot in advance

Using some boolean logic:
=((a1=2)*(a2=3)*10)+((a1=4)*(a2=5)*20)+((a1=6)*(a2=7)*30)

Put the formula in A3:
=IF(AND(A1=2,A2=3),10,IF(AND(A1=4,A2=5),20,IF(AND(A1=6,A2=7,30,"NOT ANY OF THE CHOICES")))

As a literal interpretation, this formula matches what you're looking for:
=IF(AND(A1=2,A2=3),10,IF(AND(A1=4,A2=5),20,IF(AND(A1=6,A2=7),30,"invalid values")))
However, using a lookup table might be better, like so:
The lookup table is in columns E:G, and then the formula in cell A3 is (adjust the table ranges as necessary to account for all value combinations):
=INDEX($G$2:$G$4,MATCH(A1&A2,INDEX($E$2:$E$4&$F$2:$F$4,),0))

Related

How to test cases with intervals in Excel

I have a spreadsheet with the value in A1 = 94. I would like to put in B1 a calculation such as:
if A1 is within [85;90], then B1 = A
else if A1 is within [90;95], then B1 = B
else if A1 is within [95;100], then B1 = C
is there a way to do it quickly without VBA please?
You need nested IFs
Paste this formula in B1:
=IF(A1>=85, IF(A1>=90, IF(A1>=95, IF(A1>100, "Too High", "C"), "B"), "A"), "Too Low")
If A1 = 85, 90 or 95 it will round up a category not down - to change that replace >= with > in the formula

Fill blank cell in Excel with value with same ID

I'm not so advanced in excel I need help if is it possible to do.
I have an excel with this column:
ID - Value1 - Value2
I need to update the value1 (or value2):
- only if are blank AND only if the row has the same ID
I make an example, I have this table:
ID Value1 Value2
A1 1 100
A2 2
A3 3
A4 1 200
A5 2 250
Iwould like to fill all the empty cell in this way
ID Value1 Value2
A1 1 100 200
A2 2 250
A3 3
A4 1 100 200
A5 2 250
Thank you for any help.
Ok, so your data is a mixture of numbers and texts. You can generate two new columns with the desired values using formulas. Choose two new, adjacent columns, say D and E, and enter this CSE formula in row say in cell D2:
D2:
=IFERROR(IF(ISBLANK(B2),INDEX(B$2:B$99,
MATCH(1,($A$2:$A$99=$A2)*(1-ISBLANK(B$2:B$99)),0)),B2), "")
CtrlShiftEnter
Enter the formula in D2 with CtrlShiftEnter and then copy/paste in the cells of columns D and E (or as I said any two adjacent columns).

How to change the value of a cell wiout changing the range?

I have the following columns and data:
column1
1(cell A1)
2(A2)
3(A3)
Say I want to do like transpose(A1:A3) but want to change the value of 2 in A2 to 0, "inside the transpose formula". Is this possible??? Thank you very much.
{ =TRANSPOSE(A1:A3*(ROW(A1:A3)<>2)) }
Some explanation:
We are transposing an array, not directly A1:A3 but the result of one-by-one multiplication of A1:A3 and (ROW(A1:A3)<>2)). This results in the column vector:
A1 * 1 A1
A2 * 0 = 0
A3 * 1 A3
Which is what you want to transpose.

Logical calculation in Excel

I need advice/help. I am working on calculation in excel where I have data like mentioned below.
. A B C D E F G H
1| A275 A277 A273 A777 A777 TOTAL A222 GRAND TOTAL
2| 5 7 4 3 4 7 7
Now, I want to count row 2 based on the header.
Here is the condition.
If A1 <> B1 then take A1, if B1 <> C1 then take B1, if C1 <> D1 then C1, so on.
But tricky part is...
If D1<>E1 then D1 else (if E1<>F1 then E1 else (if F1 = "TOTAL" then F1 else(if F1<>G1 then F1)))
In short H2 should have 30 and not 37.
Added comments:------------------------------------
So, Basically if A1<>B1 then take A1 but if A1=B1 then take B1, but then for B1, its a same rule like if B1<>C1 then take B1, but if B1=C1 then take C1 and for C1, same rule. Stopping point will be "TOTAL". Along with these logic I need to check if any cell in row 1 is "TOTAL" then take value for same column. Now this "TOTAL" can be in any cell in row 1.
So from above table my calculation will be 5(A2) + 7(B2) + 4(C2) + 7(F2) + 7(G2) = 30
In this calculation I have not included D2 and E2 as D2=E2 so I took D2, here E2<>F2 so I should have taken E2, but as F2="TOTAL" so I took F2 and not D2 and E2.
I hope this make sense. (Sorry, I know its confusing.)
I have data in more then 100 columns.
Can this be achieved using Macro?
------------------------------------------------------------
Another pain point is data and header are dynamic, so I can't have a fix format. Logic should be in a way that can handle the dynamic data and header.
Any help or suggestion will be greatly appreciated.
I achieved the results you want with this.
Add a helper row. In cell A3 write this formula and drag it to the right:
=IF(OR(A$1=B$1,B$1="TOTAL"),0,1)
Calculate sum in say cell H4 (not H2 because if the formula refers to entire row 2 there will be circular reference):
=SUMIF($3:$3,1,$2:$2)

assigning name on a specific character in a cell

i want to assign a name on a specific character in a cell
ex. Cell A1 is 123456HL78
i want to name the 5th character in cell B1 as:
if 5 "Branch"
if 6 "HO"
if 7 "franchise"
and the 6th character in cell C1 as:
if 6 "City"
if 7 "Province"
if 8 "Others"
therefore, result in B1=Branch and C1=City
thanks
You can do this with a lookup table and use INDEX and MATCH or VLOOKUP if you prefer along with the MID function to return the 5th or 6th character from a text string and return a specific value based on that character.
In A1 123456HL78
In B1 =INDEX($E$1:$E$2,MATCH(MID($A$1,5,1),$D$1:$D$2))
In C1 =VLOOKUP(MID($A$1,6,1),$D$1:$E$4,2)
In D1 ="5" 'The = and quotes are important, without them Match and Vlookup cannot find a match and return a #value error.
In D2 ="6"
In E1 Branch
In E2 Province
You can obviously expand this however you like. Just note the hard coded 5 in the B1 MID function because you want the 5th character, as well as the 6 in C1.
Hope this helps.
Two nested if formulas will work.
In A1 123456HL78
In B1 =IF(MID(A1,5,1) = "5","Branch",IF(MID(A1,5,1) = "6","HO",IF(MID(A1,5,1) = "7","Franchise","")))
In C1 =IF(MID(A1,6,1) = "6","City",IF(MID(A1,6,1) = "7","Province",IF(MID(A1,6,1) = "8","Others","")))

Resources