I have created a number of automated calculations for my trading business. However, I need to be able to reflect blank cells with no value at all.
You will notice that line 47 is completely filled and properly calculated. However, line 48 has no date or entry price. I need to have column P, Column Q, and Column S reflect blank. The calculation for each column is below, and the results can be seen in the picture.
Calc under P48 is:
=IF($D48="","",IF(OR(AND($D48="buy",$N48>=$C48),AND($D48="sell",$N48<=$C48)),"Win","Loss"))
Calc under Q48 is:
=IF(AND($P48="Win",$D48="buy"),ABS($N48-$C48)*10000,IF(AND($P48="Win",$D48="sell"),($C48-$N48)*10000,IF(AND($P48="Loss",$D48="buy"),($N48-$C48)*10000,IF(AND($P48="Loss",$D48="sell"),($C48-$N48)*10000))))
Lastly calc for s48 is:
=IF($P48="Loss",$Q48*1,"")
This is a very complicated and detailed spreadsheet. Can someone help me process these calculations to make them work properly?
Use the ISBLANK function.
Column D is not empty since it contains a zero on rows that do not have a date or entry price (like row 48), so I would use either the date column, the entry price column, or both.
In cell P48:
=IF(ISBLANK(B48),"",IF(OR(AND($D48="buy",$N48>=$C48),AND($D48="sell",$N48<=$C48)),"Win","Loss"))
Or - If either the date or the entry price is not filled in, your formula will return a blank cell with this in cell P48:
=IF(OR(ISBLANK(B48),ISBLANK(C48)),"",IF(OR(AND($D48="buy",$N48>=$C48),AND($D48="sell",$N48<=$C48)),"Win","Loss"))
Add ISBLANK to the beginning of columns Q & S formulas too.
S48:
=IF(ISBLANK(B48),"",IF($P48="Loss",$Q48*1,""))
The answer came through trial/error from the suggestions shown above. I also used File/Option/Advanced to remove all zero entries on the worksheet. In addition placed a blank condition in Q48.
Related
I have a calc spreedsheet, which is mostly similar to excel regarding formulas. In one sheet I have the details of some boughts I've done (comprasDet) and in another the items I can buy (productos).
The first entry in comprasDet looks like this:
I need to retreive from productos the last registered cost from "Shampo y Mascarilla Chocolate....", put it in ctUnit (that stands for unitary cost) and then calculate the entry cost in ctTot.
The last registered costs in the productos sheet are:
In this case, I need the value in the F12 cell - $6.00. Now, I know that with:
MATCH(D2,$productos.D:D,0) (written in comprasDet)
I can get the row number of "Shampo y Mascarilla Chocolate..." in productos (12), and with (formula taken from this this post):
LOOKUP(2,1/($productos.12:12<>""),$productos.12:12)
I get actually the last value in the 12th row ($6.00) - the thing is, I need to be able to look for the last price for any given value in comprasDet, for example, if instead of "Shampo y Mascarilla Chocolate..." I have "Keratina BrasileƱa (1 lt)" I'll would like to get the F4 value in productos ($7.00).
The sheet productos will be getting more columns as the prices vary, for example, in the previos print, there were only two price columns (ct20210918 and ct20211001), here is an example with another price modification:
And, in this scenario, the price I need to get from "Shampo y Mascarilla Chocolate..." with a formula inside the comprasDet sheet will be the value in productos in cell G12, $8.00.
Note: I know that in excel the notation to reference cell/s in another sheet is Sheet_name!First_cell:Last_cell, in libreoffice calc changes a little, Sheet_name.First_cell:Last_cell, but the formulas are pretty much the same.
Thanks in advance.
Edit: With the new requirements, you need to use COLUMN and MAX to find the last used column. Because you are looking for the last used column of a particular row, you need to use INDIRECT to reference only that row. Here is how you do it in excel. You will have to modify it for your program
=INDEX(productos!A:AD,MATCH(D2,productos!D:D,0),MAX(COLUMN(INDIRECT("R"&MATCH(D2,productos!D:D,0)&"C1:"&"R"&MATCH(D2,productos!D:D,0)&"C30"))))
Explanation:
MATCH(D2,productos!D:D,0) gets the correct row in the productos table. I'll call it MyRow.
INDIRECT("R"&MyRow&"C1:"&"R"&MyRow&"C30") creates a reference to the first 30 columns of MyRow. I'll call it MyRange. Note, "30" is an arbitrary number. Make it large enough that you always get the data.
COLUMN(MyRange) creates an array of column indexes for all filled cells in MyRange.
MAX(COLUMN(MyRange)) gets the largest column index, which is the last filled cell. I'll call this MyCol.
`=INDEX(productos!A:AD,MyRow,MyCol)' returns the last used column of the row you are interested in.
Original Answer:
If this was excel you would use XLOOKUP.
=XLOOKUP(D2,'productos'!D:D,'productos'!F:F,"-",0,-1)
If your program has access to the index function, this should work:
=INDEX($productos.F:F, MATCH(D2,$productos.D:D,0))
I'm entering datas in A column of a table. According to the datas, I making sums from the yellow cell (actually this yellow cell is the high value of the A column). So all 10 cells, there is a sum until the end of datas.
I'm looking for automatically report the seven first grey cells (the sums)to another table. The problem is, according to the datas, high value is not at the same place so the sums are not to the same place too.
How can I do ?
Thank you for your help
MY ERROR :
And the message when I press ctrl maj enter in same time :
You might use this array formula in your report.
=INDEX($F:$F,SMALL(ROW($F$4:$F$117)+(100*(F$4:$F$117="")), ROW(F1)))&""
Bear in mind that, as an array formula, it must be confirmed with Control+Shift+Enter. Enter the formula in the row where you have Somme = 1, then copy down to 6. Note that Row(F1) is a counter. You have a similar counter (1 to 6) in F124:F130. Therefore you can replace ROW(F1) with $F124 (if that is where the "1" is) to make it easier to understand, perhaps.
The formula retrieves the value of the 1st, 2nd, 3rd etc non-blank cell in the range F4:F117. If those cells contain a formula they will be considered "blank" if their result equals "".
BTW, if you don't always have 113 results to evaluate you might consider giving a name to the range E4:E117. For example, if you name that range as "Results" then =SUM(Results) would be the same as =SUM($E$4:$E$117), but as you insert or delete rows within the named range the formula doesn't need to be amended. Use of a named range would simplify understanding your existing formula. You could do the same with column F.
Finally I find a solution to report the values from F to another table. As values positions are dependant of the MAX raw in E (every 10 cells) I make this formula :
For the first : INDEX(E4:F117;EQUIV(GRANDE.VALEUR($E$4:$E$117;1);$E$4:$E$117;0)+10;2)
For the second :
INDEX(E4:F117;EQUIV(GRANDE.VALEUR($E$4:$E$117;1);$E$4:$E$117;0)+20;2)
Etc...
I have a spreadsheet with thousands of rows and numerous columns. What I am hoping to accomplish is to basically check column AB for a certain value. When it finds a row that contains (not exact match, just needs to include) the word "test" then I want to check if column Z (in the same row) has value "next". If both those are true, then I want to display the value from column N in that same row. What code could I use to accomplish this?
Note: I need this to list the value from column N for each row that has both "test" and "next", not just for one row.
Edit:
To clarify what I mean by multiple values see this image:
I want a formula that will list ALL of the Column N values of rows that meet have both test and next. And this list is not in the row, it is going to be one column listing each match.
Update:
I have gotten close to getting this done, this is my best formula up to this point. =ArrayFormula(IF(ISNUMBER(MATCH("*"&$A$1&"*",SID!AB:AB,0)),SID!N3,"n")) This works once, but here is what I need fixed:
This returns the first value that works, in this example Place1, but then it just lists everything form column C, even if it does not reach the requirements. Most likely an issue with my arrayformula.
Try out the below formula,
=IF(AND(ISNUMBER(MATCH("*"&"test"&"*",A1,0)),ISNUMBER(MATCH("*"&"next"&"*",B1,0))),"Column N value","")
This formula searches cell A1 for the string test (anywhere in it) and searches next in cell B1. I leave the part of replacing the cells with the required columns to you and also change the Column N value in the formula to N1
I'm learning to use array formulas and have been successful doing simple things like adding 2 columns together in a third column. For example, I can put =arrayformula(B:B+C:C) in D1 and it adds B and C for each row.
But now I have a situation where I want to subtract two numbers in the same column. I want to take the value of that column in the current row and subtract the previous row's value from it. Without array formulas this is simple: in O7 I put =N7-N6 and cop that down so O8 gets =N8-N7, etc. But that requires copying down every time - can I do the same thing with an array formula?
Basically, can I do something like =arrayformula(B:B+(B-1):(B-1)) ?
Context: column N is a monthly account balance. I would like to calculate how much that balanced changed each month. So for row 7, =N7-N6 gives me that difference. But I'm changing the entire spreadsheet to array formulas so I can stop pasting all of the formulas and I'm stuck on this one since it's comparing the same column.
I'm trying to get everything into Row 1 so my values and calculations can start in Row 2. For example, here's one of my formulas in Row 1:
arrayformula(if(row(A:A)=1,"Total gross income",if(LEN(B:B),B:B+C:C,"")))
Unfortunately, in Column O (the one I asked about originally) if I do this:
=arrayformula(if(row(A:A)=1,"Amount saved this month",if(row(A:A)>1,if(LEN(N:N),N2:N-N:N,""))))
Or this:
=arrayformula(if(row(A:A)=1,"Amount saved this month",if(row(A:A)>1,if(LEN(N:N),offset(N:N,1,0)-N:N,""))))
Every row is off by 1 - the result that should go in Row 3 goes in Row 2, etc. And if I do this:
=arrayformula(if(row(A:A)=1,"Amount saved this month",if(row(A:A)>1,if(LEN(N:N),N:N-offset(N:N,-1,0),""))))
Then it gives me an error because the offset function is trying to evaluate something out of range (possibly it starts with N1 and tries to grab a value 1 row above N1?)
Any advice on how to handle that out-of-range error?
I think the error is because of offset range N:N which starts from N1 and you are trying to shift it -1 or one cell up, which brings the formula out of sheet.
Try this formula instead:
=arrayformula(
{"Amount saved this month";
if(LEN(N2:N),N2:N-offset(N2:N,-1,0),"")})
It uses {} to make an array. See more info:
https://support.google.com/docs/answer/6208276?hl=en
Bonus. There is no reason to check row number now.
I have the following formula to return the value of the last value in a column:
=LOOKUP(2,1/(D:D<>""),D:D)
What I need now is to return the value of the cell adjacent to it as well. (It will not necessarily be the last value in that column and the info in Column D could have duplicates.
If your data looks like this:
A 1
A 2
A 3
B 4
B 5
B 6
C 7
To get last value this will do the trick:
=INDIRECT("B"&COUNTA(A:A))
And to get last where value is A:
=INDIRECT("B"&MATCH("A",A1:A7,0)+COUNTIF(A1:A7,"A")-1)
Just use next column:
=LOOKUP(2,1/(D:D<>""),E:E)
Ok, So I have found an answer by playing around with array formulas.
The problem was that this is a stock control sheet where there are changes made at multiple times, each recorded in the next available row. There is always a date (Column E) but not necessarily a Supplier, as it might be stock moving out. When a Supplier delivers, the Supplier name is recorded in Column D. In D1 the last supplier is then shown with the following formula.
=LOOKUP(2,1/(D:D<>""),D:D)
I want to then see what date it was last received. The formula I found that works is as follows (Array Formula):
=INDEX(E:E,MAX(IF(D:D=D1,ROW(D:D)-ROW(INDEX(D:D,1,1))+1)))
This is generally how I do it:
=XMATCH(FALSE,ISBLANK(A:A),0,-1)
This is what each part does:
Parameter
Explanation
FALSE
Instructs Excel to find the first instance of FALSE that it finds
ISBLANK(A:A)
Takes in the column A:A and notionally assigns a value to every item in the column
0
Means we want an exact match. Probably not necessary to put in, but I think it's good practice anyway
-1
Instructs Excel to start the search at the bottom/right of the range and work up/left. If you change this to 1 (the default), Excel will begin the search at the top/left and work down/right
So, taken together, this will search from the bottom of the column A:A, until Excel finds the first cell that is not blank, and return that cell.
Also, yes, this equation can be changed to a row format (e.g. 1:1), and can take a smaller range (e.g. A1:A20), but it cannot take a 2-dimensional range (e.g. A1:B20).
As a practical matter, this approach is much faster than other approaches (and much faster than you'd think, given it's evaluating against every row/column in the range), and won't get fooled by columns that have empty spaces in them (like with a COUNTA style approach).