Multiple Lines in Excel, need a Formula to calculate diferences - excel

I have an inventory spread sheet.
There are 5700 rows all up to column "I".
These rows have part numbers in column "A".
Column "I" contains the cost of that part based on a quantity of parts listed elsewhere in the table.
With me so far?
Lets say Row "1" contains a part number 9FH-01010 and column "I" gives a dollar value based on other criteria, (number of parts BEFORE Inventory).
Row "2" would be the same with the exception that row "2" is based on the dollar value AFTER inventory.
Is there a formula that could identify like cells in column "A" and then calculate the difference in dollar value of "I" and then place that answer in column "J"?
Here's the kicker, there are some part numbers that have only 1 entry.
Example:
"A1" = 9FH01010 "I1" = 5000.00 "J1" = -2500.00
"A2" = 9FH01010 "I2" = 2500.00
"A3" = 9FH20202 "I3" = 4300.00
"A4" = 9FH30303 "I4" = 2000.00
"A5" = 9FH30303 "I5" = 4000.00 "J5" = 2000.00
Any help on this is appreciated.

What I'm getting is that (1) in each row, there is a key in $A; there will either be exactly 1 following row with the same key, or zero rows.
Have a look at the 'IF' function. This is probably the easiest way to code the function:
IF $a is equal to $a, then compute $I - $I.
Something like this:
=IF($A2 = $A1, $I2 - $I1, ' ')

In column A of your database you have ID's for the products, but they can appear twice. One for each circumstance (AFTER and BEFORE). I advice you first to add a column to determine which one is which.
The following formula works only if each product appears twice ("after" and "before")
in a NEW column, next to I5 -for example in J5- TYPE:
=IF(VLOOKUP(A5,A$1:I4,9,)>0,I5-VLOOKUP(A5,A$1:I4,9,),"")
then copy J5 up and down through the whole column.
If you want to avoid errors (#N/A), you can do a larger formula with IFERROR function.

Based on the sample data, assuming your data is in range A1:I5700
You can enter the following formula in cell J1 and drag it down to apply across:
=IFERROR(INDEX(I2:$I$5700,MATCH(A1,A2:$A$5700,0))-I1,"")

Related

Formula to replace values If cell is not empty (e.g."Y" for yes) to be replaced by an absolute reference cell?

This may be simple - I am using a costing sheet that has been built to be somewhat of a checklist, in a row of names. I want to be able to tick or use text "Y" (Yes) if costings should be added to a person in the same cell the text was entered.
Example:
J$10 refers to a cost, I want this reference to replace entered text in a cell without having to manually click to replace certain values. In short - replacing specified text with another cell with an absolute reference of its own($).
Formula for:
IF "Y" is entered replace to J$10
at the moment I am manually pasting "J$10" (refers to a standard costing sum) next to a row of candidate names but this has a lot of columns per name under predetermined costs selections.
What Max R is hinting at: use another column for this.
J$10 holds a sum, if you were to use column K for the "Y" value, then your formula in column L would need to be:
=if(K10 = "Y", J$10, 0)
assuming you want to sum all with a "Y": you can do this on column L

EXCEL - COUNT OF Cells in column A where value is NOT Numeric BUT where Column B = "X"

Data
I have 2 columns in a table - 'AppRef' and 'HoursLost'..
AppRef contains single alpha characters (A,B,C etc)
HoursLost contains a combination of blank entries, numeric and alphanumeric values ('','ABC123',123 etc)
Im trying to obtain a Count of the number of records where HoursLost IS NOT Numeric BUT also where APPRef = "C".
Ive been struggling with COUNTIFS and SUMPRODUCT functions for some time so thought id reach out for help..
Do you know how I bring together the 2 functions to achieve this?
Try =SUMPRODUCT(--NOT(ISNUMBER(Table1[HoursLost])),--(Table1[AppRef]="C")), substituting the name of your table for Table1.
If you want to count values of AppRef containing "C" rather than identical to "C", you can change the second condition to --NOT(ISERROR(FIND("C",Table1[AppRef]))).
I have put "AppRef" in column "A" and "Hourslost" in "B".
I have created a helper column "C" with following formula:
=AND(A2="C",NOT(ISNUMBER(B2))) // for cell C2
=AND(A3="C",NOT(ISNUMBER(B3))) // for cell C3
...
At the end, I've entered following formula:
=COUNTIF(C2:C10,TRUE)

How to repeat the condition until the new value is seen or reached?

I have the following formula for getting the value from another sheet if the specific cell on it has the value of "x".
=IF(SheetName!CellToCompare="x",SheetName!CellValue)
The problem is if the column doesn't have a value of "x" it will return the value of "False".
What I want is something like a loop where it will check if the value of "x" exists, if not then ignore the "false" return and continue to the next cell until it gets another "x".
Here's the example of the sheet where I want to get the value.
Sheet1
With the formula of =IF(Sheet1!B2="x",Sheet1!A2), the result will be; Result
What I want is something like this.
Anyone can help me?
EDIT: I have Office Pro Plus 2019
=IFERROR(INDEX(Sheet1!$A$1:$A$50,SMALL(IF(Sheet1!B$1:B$50="x",ROW(Sheet1!B$1:B$50)-ROW($A$1)+1),ROW()-1)),"")
If in cell A1 you have Value 1 in the sheet you want to get your list, in A2 enter this array formula with ctrl + shift + enter and drag down / to the right.
I used row 1 to 50 for this, but change that to the actual range.
The formula checks for the row number which has an x and returns these from small to large for the indeed of the row containing the strings.

How can I keep the same cell reference in if function, until the if function is true/false?

I have the following function in excel:
INDIRECT(CHAR(COLUMN()+53)&O1+1)
This function has to be the outcome of an if-statement when the statement is true. I don't want the O1 to change to O2, O3, etc.. when I drag the function down, until the statement is true. From there I want the function to change this cell reference in ascending order. So as long as the if statement is false, the reference needs to be O1.
I know that absolute referencing can be used to keep the same cell-reference ($O$1), but then the cell reference doesn't change when the statement is true either.
My data looks like this: enter image description here
My complete formula looks like this: enter image description here
=IF(P2=INDIRECT(CHAR(COLUMN()+51)&O1+1);IF(INDIRECT(CHAR(COLUMN()+51)&O2+1)="";INDIRECT(CHAR(COLUMN()+53)&O1+1);INDIRECT(CHAR(COLUMN()+51)&O2+1));IF(INDIRECT(CHAR(COLUMN()+53)&O2+1)="";"";INDIRECT(CHAR(COLUMN()+51)&O2+1)))
What I want to do is to fill a column with values of the first column in the data until the cells are empty. Then I want to fill the column with data from the i+2th column (so from column C I go to column E). In order for this to happen, I want the first cell of (column E in this case) to stay the same, until column C is empty and the column starts taking values from column E.
I hope that this description gives a clear view of what I want to do.
Thanks in advance.
What I want to do is to fill a column with values of the first column in the data until the cells are empty. Then I want to fill the column with data from the i+2th column (so from column C I go to column E). In order for this to happen, I want the first cell of (column E in this case) to stay the same, until column C is empty and the column starts taking values from column E.
It's not the same kind of solution, but this might suit your needs better than your original formula:
=
IFERROR(INDEX(OFFSET($A$1,2,0,COUNTA(A:A)-1,1),ROW($A1)+0),
IFERROR(INDEX(OFFSET($B$1,2,0,COUNTA(B:B)-1,1),ROW($A1)+1-COUNTA(A:A)),
""))
If you need it for more than 2 columns, just extend the formula by following this pattern:
=
IFERROR(INDEX(OFFSET($A$1,2,0,COUNTA(A:A)-1,1),ROW($A1)+0),
IFERROR(INDEX(OFFSET($B$1,2,0,COUNTA(B:B)-1,1),ROW($A1)+1-COUNTA(A:A)),
IFERROR(INDEX(OFFSET($C$1,2,0,COUNTA(C:C)-1,1),ROW($A1)+2-COUNTA(A:A)-COUNTA(B:B)),
IFERROR(INDEX(OFFSET($D$1,2,0,COUNTA(D:D)-1,1),ROW($A1)+3-COUNTA(A:A)-COUNTA(B:B)-COUNTA(C:C)),
""))))
Sample implementation: https://i.stack.imgur.com/MAtxW.png
I've made considerations for your extra blank row between the header and the first row of data. For anyone wanting to use this formula without the blank row in their data set simply change the Offset-Row parameter from 2 to 1:
=
IFERROR(INDEX(OFFSET($A$1,1,0,COUNTA(A:A)-1,1),ROW($A1)+0),
IFERROR(INDEX(OFFSET($B$1,1,0,COUNTA(B:B)-1,1),ROW($A1)+1-COUNTA(A:A)),
""))
You can stick the formula anywhere in your worksheet, but don't forget to change the column letters to suit the location of your fields. In your case, probably:
=
IFERROR(INDEX(OFFSET($C$1,2,0,COUNTA(C:C)-1,1),ROW($C1)+0),
IFERROR(INDEX(OFFSET($E$1,2,0,COUNTA(E:E)-1,1),ROW($C1)+1-COUNTA(C:C)),
""))
Be aware that you need to make sure your columns don't contain rows with blank cells in between names, as this will cause it to skip an equal number of names at the bottom of the column.
EDIT:
I just realized your system uses semi-colons ";" to parse Excel formulas (mine uses commas ","). Please take note of that when copying these formulas to your spreadsheets. Here's the formula again but using ";"...
=
IFERROR(INDEX(OFFSET($C$1;2;0;COUNTA(C:C)-1;1);ROW($C1)+0);
IFERROR(INDEX(OFFSET($E$1;2;0;COUNTA(E:E)-1;1);ROW($C1)+1-COUNTA(C:C));
""))

Excel INDEX and MATCH Get Value

I have an excel workbook that I need some help with INDEX and MATCH or any other Formula that can get me my end result.
Here is sheet1:
SIT_ID METER SUSE_CD
10834282 DT0061 B
10834282 AW7931 P
21676286 CQ9635 P
21676286 DP4838 B
21726281 AW7880 P
21726281 DT0032 B
Here is Sheet2:
Site ID B P
10834282
21676286
21726281
Ultimately what I am trying to do is on Sheet2 is put the Meter that = B for the SITEID in the column and then Put the Meter that = P in the Same row.
I have never used Index or Match and I looked it up online but I am confused and hoping someone can help me with the correct formula or point me in the right direction.
Thanks so much!
INDEX first takes a range, then a row number, an optional column number (and an optional area number).
MATCH takes a value to lookup, an array and a mode.
In your problem you can use the following in Sheet2 cell B2:
=INDEX(Sheet1!$B$2:$B$7, MATCH($A2, IF(Sheet1!$C$2:$C$7=B$1,Sheet1!$A$2:$A$7), 0))
This formula is an array formula and will work with Ctrl+Shift+Enter and then you can fill it to the other cells.
I had to use an IF because there're two conditions to check.
EDIT: Use this one if your cell formats are different:
=INDEX(Sheet1!$B$2:$B$7,MATCH($A2*1,IF(Sheet1!$C$2:$C$7=B$1,Sheet1!$A$2:$A$7*1),0))
EDIT2: Adding trimming:
=INDEX(Sheet1!$B$2:$B$7,MATCH($A2*1,IF(TRIM(Sheet1!$C$2:$C$7)=TRIM(B$1),Sheet1!$A$2:$A$7*1),0))
EDIT3: If you're using it on your full data, change the range:
=INDEX(Sheet1!$B:$B,MATCH($A2*1,IF(TRIM(Sheet1!$C:$C)=TRIM(B$1),Sheet1!$A:$A*1),0))
Assuming your Sheet1 looks like this:
And your Sheet2 looks like this:
The formula in Sheet2 cell B2 and copied over and down to cell C4 is:
=INDEX(Sheet1!$B$2:$B$7,MATCH(1,INDEX((Sheet1!$A$2:$A$7=$A2)*(Sheet1!$C$2:$C$7=B$1),),0))
Note that this is a regular formula, so no need for Ctrl+Shift+Enter
A helper column D is added to initial columns.
D2: =$A2 & $C2
Now it's possible to make a simple search of the concatenated SITE_ID and SUSE_CD:
H2: =MATCH($G2&" B";$D$2:$D$8;0)
The result would be a row number (=1 in this case) for the needed string in array $D$2:$D$8.
INDEX shows the value of the cell, found by counting n-th row (defined by MATCH) and m-th column (=2) in array $A2:$A$8 from the upper left cell (A2).
Altogether: =INDEX($A$2:$B$8;MATCH($G2&" B";$D$2:$D$8;0);2)
The easiest way to get around with this is,
to use concatenation operator in the match function.
Don't forget to use Ctrl+Shift+Enter
Use below formula in column B of Sheet 2
{=INDEX(Sheet1!$B:$B,MATCH(Sheet2!$A2&Sheet2!$B$1,Sheet1!$A:$A&Sheet1!$C:$C,0))}
And the below formula in column C of Sheet 2
{=INDEX(Sheet1!$B:$B,MATCH(Sheet2!$A2&Sheet2!$C$1,Sheet1!$A:$A&Sheet1!$C:$C,0))}
And then flash fill the remaining rows.

Resources