Hi!
Can any one show me example, how I can write this in Excel.
Thanks.
Consider:
=IF(AND(200<=A1,A1<340),1,IF(AND(27<=A1,A1<80),2,IF(AND(16<=A1,A1<24),3,IF(AND(5<=A1,A1<12),4,IF(AND(-10<=A1,A1<2),5,"X")))))
This represents your logic as nested ifs. The X represents the else.
(this assumes the syntax of your Post conveys 1, 2, 3, 4, 5 as the values of the output.)
EDIT#1:
This formula handles the 500 case:
=IF(OR(AND(200<=A1,A1<340),A1=500),1,IF(AND(27<=A1,A1<80),2,IF(AND(16<=A1,A1<24),3,IF(AND(5<=A1,A1<12),4,IF(AND(-10<=A1,A1<2),5,"X")))))
Related
I created a range using INDIREKT, I added COL() to see how big this range is:
=COL(INDIRECT("R1C1:R1C5"; 0))
As you can see, I'm using the R/C notation for row/colum adressing. The result is simply all numbers from 1 to 5 in the first row:
Now I'm just using the numbers to address letters from a string, like this:
="_" & MID("HELLO"; COL(INDIRECT("Z1S1:Z1S5"; 0)); 1)
This works as expected and returns:
Now there's a random cell somewhere on the sheet, I named this cell "_H". The cell just contains the letter H:
I did this for E, L and O, too.
Now I add a third row containing this.
=INDEX(INDIRECT(A2);1;1)
Pulling this to the width of 5 columns the result is as expected:
And here comes my problem: How to use the R/C notation? This comes into my mind:
=INDIRECT("Z2S1"; 0)
This returns the correct value of row 2, column 1 aka A2. Which is _H. Now I put this into the INDEX formula, expecting that Excel takes the _H, use this as the address for INDEX and returns the value from 1;1 of this "name range":
=INDEX(INDIRECT("R2C1";0);1;1)
But the result is simply:
When I remove the quotes, Excel is complaining, so this is not working:
=INDEX(INDIRECT(R2C1;0);1;1)
(Apparently, because the Excel setting says I prefer A1-notation).
But I wonder why it's not working, when I tell excel explicitly to use the R/C notation?
Well, it seems like Excel just takes the range and the value from R1C1 in this range - which is _R. So I was trying around to make this column-argument "dynamic". I know that this returns the column index for the whole range.
=COL(INDIRECT("R1C1:R1C5";0))
This returns 1, 2, 3, 4 and 5 for the particular columns.
So why not putting it into the formula above:
=INDEX(INDIRECT("Z2S" & COL(INDIRECT("R1C1:R1C5";0));0);1;COL(INDIRECT("R1C1:R1C5";0)))
This returns #VALUE as an error.
How to indirectly address a cell or even a range to get a value from a particular coordinate (using INDEX)? I specifically need the R/C notation because I need to address ranges numerically (for example column 1 instead of column A and so on).
You can condense your solution - no `INDEX(X;1;1) needed:
=LET(word,"HELLO",
singleCharacters,"_" & MID(word,SEQUENCE(1,LEN(word)),1),
MAP(singleCharacters,LAMBDA(a,INDIRECT(a))))
Using LET makes it a bit more readable.
Ok, it's easier than I thought, Excel has this wonderful MAP formula:
=MAP(A2:E2; LAMBDA(a; INDEX(INDIRECT(a); 1; 1)))
Now every particular column points to the reference/range name and INDEX can use this, to get the value from R1/C1 of the particular named range.
This can even be more improved into a one-liner:
=MAP(SEQUENCE(1;LEN("HELLO")); LAMBDA(i; INDEX(INDIRECT("_" & MID("HELLO"; i; 1));1;1)))
I can put this everywhere I want, I just need to define the named ranges.
Appreciation to #Ike who lead into the right direction.
I have a list of values between 1 and 100, essentially a sort of ranking that occassionally skips a few numbers (for example, the first ten values are 2, 6, 6, 10, 10, 10, 10, 11, 12, 13). They're ordered ascendingly, so every number will be either higher than or equal to the number above it. Now, I wish to remove all the duplicates from this list while remaining between 1 and 100. So, for example, for the values above, something like 2, 6, 7, 10, 11, 12, 13, 14, 15, 16 would work or 2, 6, 7, 8, 9, 10, 11, 12, 13, 14. However, the formulas I've tried so far will either go over 100, go under 1, or create circular references.
Given the nature of the list, there's very little chance of the amount of values exceeding 100, so if that possibility can be accounted for, it'd be a nice bonus, but it's not required.
Please create a named range for all your numbers and name it Source. As an alternative, replace the named range Source in my formulas below with the sheet address of the range where you have your numbers.
[C2] =INDEX(Source,MATCH(0,COUNTIF($C$1:$C1,Source),0))
This is an array formula and needs to be confirmed with Ctl + Shift + Enter. Observe that the COUNTIF range is defined one row above the row in which the formula resides. Its formulated with one absolute and one relative end. The end of the range will expand as you copy the formula down.
You can achieve a similar result using the LOOKUP() function. But since MATCH() finds the first instance, LOOKUP() returns the last. Therefore the formula below will return the same sequence in descending order. LOOKUP() is capable of looping on its own and the formula doesn't require array enabling. Just confirm it normally, with only Enter.
[E2] =LOOKUP(2,1/(COUNTIF($E$1:E1,Source)=0),Source)
Observe that the result range is defined with an absolute and relative end, starting above the row of the formula as explained above.
In B2, formula copied down :
=IF(A2="","",IF((COUNTIF(B$1:B1,A2)>0)+(A2=A1),B1+1,A2))
Edit #1
If data have repeated 100 as per OP's comment, then B2 formula become :
=IF((COUNTIF(B$1:B1,100)>0)+(A2=""),"",IF((COUNTIF(B$1:B1,A2)>0)+(A2=A1),B1+1,A2))
Thank you everyone for posting! Thanks to Bosco's original reply, I managed to fiddle around and find the answer myself. The biggest issue I was facing was getting a circular formula error, but by using Bosco's formula as a help column I was able to get it all worked out.
So, the solution holds 3 different columns: Original Data (column A), Help Column (column B) and Final Result (column C).
In the Help Column, I did as suggested, in cell B2 and copied down:
=IF(A2="","",IF((COUNTIF(B$1:B1,A2)>0)+(A2=A1),B1+1,A2))
This would occassionally create results over 100, so in the Final Column I placed the following array formula, which incidentally also accounts for lists longer than 100 entries, in C2 and copied down:
=IF(B2="","",IF(ROW(C2)>101,ROW(C2),IF(AND(B2>=100,B3=""),100,IF($B2:$B$1000>=C3,C3-1,B2))))
As an array formula, this needs to be entered using Ctrl+Shift+Enter.
Thank you very much to everyone who posted replies, I'm sorry for my lack of clarity!
I have a table where I an looking at time between orders. it looks something like this;
weeks 1, 2, 3, 4, 5, 6, 7, 8, 9
orders 1, 2, 0, 0, 1, 2, 3, 4, 5
where zero is an order present for that week overwise the cell is 1 + the previous week number.
I need to find the column ref for the second instance of zero (to find out how long the first order has lasted)
I'm trying to use something like:
=SMALL(IF(A2:H2=0,COLUMN(A2:H2),""),2)
But all I get #Value! error.
When I evaluate the error it seems it doesn't like the "A2:H2=0" calculation in the IF. I checked I wasn't screwing up something simple in the insert function tool and on here it gives me the value I want but on the sheet just gives me the #value! error...
I tried this with index too but can't seem to get it to work.
Does anyone have any advice to where I'm going wrong?
Thanks for your help!
your formula is correct, but you should make it an array formula. Go into the cell where the formula is placed and hit CTRL+SHIFT+ENTER. your formula gets { } wrapped around itself and shows the desired result.
in row 3, I have an array of data that contains numerical values and text in the form of "n.a.". I would be most appreciative if someone could help me construct a formula that looks across the array and returns the nth non-"n.a." value.
Row 3 beginning in column B: 5, 8, n.a., 7, 6 ,3, 9, 7, n.a., 12
Formula would return 7 if n was set to 3.
Formula would return 12 if n was set to 9.
Thanks in advance.
Treat the bold, italic 3 in the formula as your n value:
=INDEX(3:3,SMALL(INDEX(ISNUMBER(B3:K3)*COLUMN(B3:K3),),3+COUNTA(B3:K3)-COUNT(B3:K3)))
Note that given your example, setting n to 9 will result in a #NUM! error because there are only 8 numbers. Expand the B3:K3 to suit your range, but do not use a whole row reference (using whole row reference would greatly decrease performance time). If preferred, you could create a dynamic named range instead of manually setting the B3:K3 range.
Try
=INDEX(3:3,AGGREGATE(15,6,COLUMN(B3:K3)/ISNUMBER(B3:K3),3))
This formula comes almost directly from God, a.k.a. Scott Craner. The way it works is that any cells which don't contain a number will give a #DIV/0! error in the division. Any cells which do contain a number just give the column in B3:K3. Aggregate with 15,6 works like SMALL but ignores the error cells thus giving you the answer you want.
I have an Excel file with these columns and values:
<-To be:
I can easily insert a PivotTable and make the array but I need a formula that will add an x if a is present in 1, 3, 4, 5 and the same for b: if is present in 1 add an x, if is present in 5 add an x etc.
Is it something that can be done using an INDEX/MATCH or should a VB script be used instead?
Based on the layout from your images, you can enter this formula in cell B2 of the report sheet:
=REPT("x",0<COUNTIFS(Sheet1!$A:$A,B$1,Sheet1!$B:$B,$A2))
...and then copy over and down as far as needed.
Note: this assumes that the source list is on Sheet1.
An alternative to COUNTIFS:
=IF(SUMPRODUCT((B$1=Sheet1!$A$2:$A$10)*($A2=Sheet1!$B$2:$B$10)),"x","")