I currently have a google sheet in which I count values in Column L against a reference sheet 'Ref' and then against a status Column W
IF(AND(COUNTIF(Ref!$A$1:$A$100,L2),W2 <>"Cancelled",W2 <>"Postponed",W2 <> "Dropped"),"Y", "N")
However the values have now changed in Column L. Instead of defined values in each cell they will be a string of values in each cell, the permutations will be too great to enter into my reference sheet.
How do I still count the values in column L to correctly return a 'Y' or 'N'
I have tried
=IF(AND(COUNTIF(L2,{"*LEE*","*LON*","*LAM*"}),W2 <>"Cancelled",W2 <>"Postponed",W2 <> "Dropped"),"Y", "N")
=IF(AND(COUNTIF(Ref!$A$1:$A$100,"*"&L2&"*"),W2 <>"Cancelled",W2 <>"Postponed",W2 <> "Dropped"),"Y", "N")
=IF(AND(COUNTIF(L2,{"*LEE*","*LON*","*LAM*"}),W2 <>"Cancelled",W2 <>"Postponed",W2 <> "Dropped"),"Y", "N")
The values I which need to count will feature one of the following phrases 'LEE', 'LON','LAM'.
The new values that are entered into column L will look like the following
<Area1: Y - LEE>,<Area2: Y - MIL>
<Area3: WF>,<Area4: Y - MUN>
<Area1: YY - MUN>,<Area2: YY - LON>,<Area3: YY-LAM>
So I need to be able to search within the cell for 1 of the 3 phrases.
Any help greatly appreciated
Thanks
I have a solution that might work, using arrayformula() in a single cell.
If I've understood correctly, it looks like you're checking Col L to see if cells contain LEE LON or LAM. You're also checking to see that they appear in Ref!$A$1:$A$100.
On your sheet that contains col F and Col W (Status), try this in row 1 (I've used AB1):
=arrayformula({"Check";if(if(L2:L<>"",regexreplace(regexreplace(regexreplace(flatten(query(transpose({if(regexmatch(split(regexreplace(L2:L,"[^A-Z]",char(9999)),char(9999)),"LAM|LEE|LON"),split(regexreplace(L2:L,"[^A-Z]",char(9999)),char(9999)),"|")}),"",9^9)),"\ ",""),"(\|)+","\|"),"^\||\|$",),)<>"",if(REGEXMATCH(join(" ",Ref!A2:A),if(L2:L<>"",regexreplace(regexreplace(regexreplace(flatten(query(transpose({if(regexmatch(split(regexreplace(L2:L,"[^A-Z]",char(9999)),char(9999)),"LAM|LEE|LON"),split(regexreplace(L2:L,"[^A-Z]",char(9999)),char(9999)),"|")}),"",9^9)),"\ ",""),"(\|)+","\|"),"^\||\|$",),)),if(regexmatch(W2:W,"Cancelled|Postponed|Dropped"),"N","Y"),),)})
To show the working, I've got three helper columns, AD, AE and AF:
AD1 gets LAM LEE or LON from col L:
=arrayformula({"LAM|LEE|LON entry";if(L2:L<>"",regexreplace(regexreplace(regexreplace(flatten(query(transpose({if(regexmatch(split(regexreplace(L2:L,"[^A-Z]",char(9999)),char(9999)),"LAM|LEE|LON"),split(regexreplace(L2:L,"[^A-Z]",char(9999)),char(9999)),"|")}),"",9^9)),"\ ",""),"(\|)+","\|"),"^\||\|$",),)})
AE1 checks the values in col AD to see if they appear in Ref!A2:A:
=arrayformula({"LAM|LEE|LON match";if(AD2:AD<>"",REGEXMATCH(join(" ",Ref!A2:A),AD2:AD),)})
AF1 checks if the value in col AE is true, then the status from col W:
=arrayformula({"Check";if(AE2:AE=true,if(regexmatch(W2:W,"Cancelled|Postponed|Dropped"),"N","Y"),)})
The 3 helper columns are combined in AB1.
Related
I want to combine multiple columns in a Google sheet into one cell, including headers / labels. My input sheet looks like this:
Name
Description
Col 1
Col 2
Col 3
Foo
val 1
val 2
val 3
Bar
val x
val y
val z
And I want to concatenate the values in each column into a single cell, including the headers for each value. Desired output:
Name
Description
Foo
Col 1val 1Col 2val 2Col 3val 3
Bar
Col 1val xCol 2val yCol 3val z
This formula concatenates the columns into one, however it doesn't include the headers (note that char(10) produces a linebreak):
=TEXTJOIN(char(10),true,B2:E2)
I can produce a similar result using REDUCE (I can't believe I'm writing a reducer in a Google Sheet):
=REDUCE("", B2:E2, LAMBDA(accumulator, current_value, CONCATENATE(accumulator, current_value, char(10))))
However the lambda function doesn't seem to provide the index of the current iteration, so I'm not sure how to grab the column name above it.
Use this formula
=ARRAYFORMULA(
QUERY({"Description";
TRIM(SUBSTITUTE(FLATTEN(QUERY(TRANSPOSE(
IF(B2:D="",,","&B1:D1&","&B2:D&",")),"",9^9)),",",CHAR(10)))},
" Where Col1 is not null" ) )
try the old way:
=ARRAYFORMULA(TRIM(REGEXREPLACE(TRIM(FLATTEN(QUERY(TRANSPOSE(
IF(B2:D="",,"×"&B1:D1&"×"&B2:D&"×")),,9^9))), "×", CHAR(10))))
or in one cell if that's what you want:
=INDEX(TRIM(REDUCE(, B1:D1&CHAR(10)&B2:D3&CHAR(10),
LAMBDA(a, c, a&c&CHAR(10)))))
Using your current TEXTJOIN() formula you can just include the Column Headers with the dollar sign ($) which means absolute reference so it will not change when copied/dragged down to rows below.
Try:
=TEXTJOIN(char(10),true,C$1,C2,char(10),D$1,D2,char(10),E$1,E2)
Drag down to rows.
Result:
Refer to this link for more info on Absolute Reference: https://www.lido.app/tutorials/absolute-reference-on-google-sheets
Struggling to get this to work as I need. Basically a set of nested IF formulas with some conditions (see bottom of post for the rules)
I have 3 columns - J, K and L
Column J
contains the last login date (represented by 01/01/1970 if it's never been logged into)
Column K contains the last interaction date (represented by 01/01/1970 if no interaction or blank if within the last 90 days)
Column L contains the last activity date for a different metric. (blank if within the last 90 days)
I have another column, M - which I am intending to use as the calculated field.
This is what I am trying to achieve:
J
K
L
M
01/01/1970
01/01/1970
Recent Activity
26/06/2021
26/06/2021
01/01/1970
01/02/2021
Recent Activity
30/06/2021
01/01/1970
23/03/2020
30/06/2021
So the rules are as follows:
If Col J contains 01/01/1970 OR Col J date is before 25/03/2021 then check Col K.
If Col K contains 01/01/1970 then check Col L. If Col K IS BLANK then show "Recent Activity"
If Col L IS NOT BLANK then show Col L Date. If Col L IS BLANK then show "Recent Activity"
If Cols J, K and L all contain a date, get the most recent date from them
I have pulled out a few tufts of hair trying to get this to work, so any help would be greatly appreciated!
Looking at your rules, is 25/03/2021 a static date or should it be derived from a value somewhere? If static, then try this for the IF statements:
=arrayformula(if(J1:J<>"",if(isblank(J1:J)+isblank(K1:K)+isblank(L1:L)=0,if(K1:K>J1:J,if(L1:L>K1:K,L1:L,K1:K),if(L1:L>J1:J,L1:L,J1:J)),if(J1:J<datevalue("2021-03-25"),if(K1:K=datevalue("1970-01-01"),if(L1:L<>"",L1:L,"Recent Activity"),"Recent Activity"),J1:J)),))
There might be better functions, but this is mainly done with IF().
if(J1:J<>"" will run the subsequent formula as long as there are values in col J.
if(isblank(J1:J)+isblank(K1:K)+isblank(L1:L)=0 checks each row to see if there is a date in col J, K and L.
If there is, then this gets the largest date (it's a bit clumsy but someone else might be able to help):
if(K1:K>J1:J,if(L1:L>K1:K,L1:L,K1:K),if(L1:L>J1:J,L1:L,J1:J))
An alternative to finding the largest date on each row could be:
transpose(dmax(transpose(J:L),{sequence(1,max(if(J:L<>"",row(J:J))))},{J:L}))
or:
query(transpose(query(transpose(J1:L),"select "®exreplace(join("","Max(Col"&sequence(max(if(J:L<>"",row(J:J))))&"),"),",$",)&" ",0)),"select Col2",0)
The other IFs test out the other scenarios.
based on your rules try in row 1:
=INDEX(IF(ISDATE_STRICT(I:I)*ISDATE_STRICT(J:J)*ISDATE_STRICT(K:K),
VLOOKUP(ROW(I:I), SPLIT(SORT(FLATTEN(ROW(I:I)&" "&I:J), 1, ), " "), 2, ),
IF(LEN(I:I&J:J&K:K), IF(I:I<"25/03/2021"*1, IF(J:J="01/01/1970"*1,
IF(((I:I="01/01/1970"*1)+(I:I<"25/03/2021"*1))*(J:J="01/01/1970"*1),
"Recent Activity", ), "Recent Activity"), I:I), )))
I think doing this as an arrayformula is unnecessarily complicated.
Here is a sample sheet made specifically for this question. In it, i placed this formula in cell M2 on a tab called MK.Idea and dragged it down:
=IF(J2,IF(J2>1*"25/3/21",J2,IFERROR(1/(1/MIN(N(K2),N(L2))),"Recent Activity")),)
Does it give the expected results? maybe you could add some more sample data on the sheet and test it out?
This is my formula:
=SUMIFS(Transactions!$B2:$B1000, "=2020_10", Transactions!$H2:$H1000, "=Salary", Transactions!$E2:$E1000)
So I'm trying to say "if the row has a date (string) of 2020_10 in col B, and a value of "Salary" in col H, add up col E (which contains a monetary amount)"
As you can see I've tried specifying the exact number of rows to try and ensure the "array arguments" are of the same size but it still throw the same error.
Transactions sheet:
Formula for col B (date as a string): =IF(ISBLANK(A1000), "None", CONCATENATE(YEAR(A1000), "_", MONTH(A1000)))
Formula for col H (Calculated Purchase Type): =IF(ISBLANK(G1000), "None", G1000)
Col E: manually entered number
Screenshot of transactions sheet:
So I'd like row 9 counted in the SUMIFS, but not the other rows (as their Calculated Purchase Type (col H) isn't "Salary").
You seem to have the arguments in the wrong order.
The syntax of the function is:
SUMIFS(sum_range, criteria_range1, criterion1, [criteria_range2, criterion2, ...])
So it's trying to sum the contents of column B, and using "=2020_10" and "=Salary" as criteria ranges.
Try
=SUMIFS(Transactions!$E2:$E1000, Transactions!$B2:$B1000, "=2020_10", Transactions!$H2:$H1000, "=Salary")
I had the arguments in the wrong order. The range you want to add up goes first:
Wrong:
=SUMIFS(Transactions!$B2:$B1000, "=2020_10", Transactions!$H2:$H1000, "=Salary", Transactions!$E2:$E1000)
Correct:
=SUMIFS(Transactions!$E2:$E1000, Transactions!$B2:$B1000, "=2020_10", Transactions!$H2:$H1000, "=Salary")
This is because I adapted an existing SUMIF (singular), which takes the range you want to add up first. Why did they swap them lol.
Thank you for your time!
I am trying to make a trade journal in Google Spreadsheets.
What I want is the entry price and exit price of the trades,
Which are cell C10 and cell C11 in the screenshot image below.
I just manually typed the correct value - 960 and 2200.
Fortunately, the entry price for C10 is always what's in cell H2,
Because the first input will always be "Buy" in column F.
However I'm stuck finding the exit value.
I want it to find the last non-zero value of column H, only when column F contains "Sell".
What formula can I write?
enter image description here
You can do it with a combination of
INDEX
QUERY
COUNTA
Query for entries in column H where F is equal to "sell" and H is not 0.
From the retrieved subset of data, get the one with the last index (by counting the total amount of indices with COUNTA).
Sample formula:
=INDEX(
QUERY(F2:H, "select H where (F = 'sell' and H <> 0)"),
COUNTA(
QUERY(F2:H, "select H where (F = 'sell' and H <> 0)")
),
1
)
You can also do it without QUERY() (even though it is a really cool function).
=INDEX(H:H,MAX(IF((F:F="Sell")*H:H,ROW(F:F)),-1))
Find last row number where "Sell" appears in Column F and the corresponding value in Column H is non-zero. Since the row number monotonically increases, MAX() always gives us the last occurrence. If the row says "Buy" instead, or the value is 0, then IF() returns -1. We cannot use 0 because INDEX() evidently returns the whole range if we do that.
Use that row number as an index for column H to get the corresponding value. If no valid value was found, we get a #NUM error, which you can handle with IFERROR() if you'd like.
Note: we can't use a VLOOKUP() and approximate match because Action is unsorted.
Given a spreadsheet with two columns, say A and B, each containing n values under it, all text; is there a formula that allows me to fill just one cell containing the amount of equal values in columns A and B?
Example:
A B
-----
1 M M
2 L M
3 L L
4 M M
5 M L
-----
3
Since columns A and B both contain an M in rows 1 and 4, and an L in row 3, the result is (i.e. 2+1).
A simple solution is to use QUERY function in google spreadsheet:
=SUM(QUERY(A1:B5, "Select 1 where A = B"))
Or using SUMPRODUCT:
=ARRAYFORMULA(SUM(((A:A)=(B:B)) * (1) ))
One of possible solution will be to add the following formula in column C: =N(EXACT(A1,B1)),
copy it throughout the column down to the last row and then sum up the column C values using =SUM(C1:C5).
Here we go:
=IF(EQ(LEFT(A0, 1), "A"),
SUM(ARRAYFORMULA(N(EXACT(TRANSPOSE(A1:A5), TRANSPOSE(B1:B5))))),
"")
Reading: if the value in row 0 (it doesn't exist, but my example above does ;) ) is equal to the text "A", take the sum of an array N, otherwise put in an empty string. ("")
Array N is build by taking the transpose of columns A and B. (Turning them, so they look like a row) and comparing the values. (Burnash gave me the options "N" and "EXACT") The formula N transforms this into a 1 or 0.
Copy paste the formula in an entire row and what do you know... It worked! That was hellish for something so trivial.
Thanks anyway.