I would like my spreadsheet to count the current win streak.
For example:
If DE match history looks like W W W L W W then I would like the current win streak to say W2. If DK match history looks like L L W L L L then I would like the current win streak to say L3.
Here is an example spreadsheet,
https://docs.google.com/spreadsheets/d/1NROEe3VOAXDDianHcLk3y6YSBLNGMAj3t9GC4WJDvwM/edit?usp=sharing
From Tom's comments, this worked for me:
=REGEXEXTRACT(JOIN("",D2:R2),"(L|W)*$") & LEN(REGEXEXTRACT(JOIN("",D2:R2),"(L*|W*)$"))
I suggest using a regex to find consecutive W's or L's at the end of the list:
=iferror(regexextract(textjoin("",true,E2:2),"W+$"),regexextract(textjoin("",true,E2:2),"L+$"))
This formula will ignore any empty cells.
Or to put it in W2, L2 format:
=iferror("W"&len(regexextract(textjoin("",true,E2:2),"W+$")),"L"&len(regexextract(textjoin("",true,E2:2),"L+$")))
Related
I recently posted on here to get help with a formula, here is the link...https://stackoverflow.com/questions/75068029/vlook-up-style-forumla-but-range-is-2-cells A user called rockinfreakshow was really awesome and provided a great solution for me. I'm not very experienced and don't understand what the formula at all but I'd love to be able to add more attributes to it. Is anyone able to help break it down for me ?
I havent tried anything here, it's totally out of my realm of understanding
=MAKEARRAY(COUNTA(B2:B),COUNTA(D1:O1),LAMBDA(r,c,IF(REGEXMATCH(LAMBDA(ax,bx,IFS(REGEXMATCH(ax,"Mixed")*REGEXMATCH(INDEX(C2:C,r),"Blend")*REGEXMATCH(INDEX(C2:C,r),"Filter"),"BLEND-"&bx&"|FILTER-"&bx,REGEXMATCH(ax,"Mixed")*NOT(REGEXMATCH(INDEX(C2:C,r),"Blend"))*REGEXMATCH(INDEX(C2:C,r),"Filter"),"ESP-"&bx&"|FILTER-"&bx,REGEXMATCH(ax,"Mixed")*NOT(REGEXMATCH(INDEX(C2:C,r),"Filter")),"BLEND-"&bx&"|ESP-"&bx,LEN(ax),SUBSTITUTE(ax&"-"&bx,"Espresso","ESP")))(regexextract(INDEX(B2:B,r),"([^\s]*?) Subscription"),IFNA(SWITCH(REGEXEXTRACT(INDEX(C2:C,r),"Small|Medium|Large"),"Small",250,"Medium",450,"Large",900),SWITCH(REGEXEXTRACT(INDEX(B2:B,r),"Medium|Large"),"Medium",225,"Large",450))),"(?i)"&INDEX(D1:O1,,c)),1,)))
see the WHY LAMBDA? part of this answer to understand the LAMBDA
the formula contains 2x LAMBDA and there are a total of 4 placeholders which translates to:
r - COUNTA(B2:B)
c - COUNTA(D1:O1)
ax - REGEXEXTRACT(INDEX(B2:B, r), "([^\s]*?) Subscription")
bx - IFNA(SWITCH(REGEXEXTRACT(INDEX(C2:C, r), "Small|Medium|Large"),
"Small", 250, "Medium", 450, "Large", 900),
SWITCH(REGEXEXTRACT(INDEX(B2:B, r), "Medium|Large"),
"Medium", 225, "Large", 450))
r counts how many items are in B column
c counts how many items are in row 1 of range D1:O1
ax extracts the word from B column that precedes the word Subscription
bx is a bit complex but essentially it extracts from C column word Small or Medium or Large and replaces it with 250, 450 or 900 respectively. then if C column does not contain one of those 3 words it checks for Medium or Large within B column and assigns 225 or 450 respectively
what we are left with is the core of the formula:
IFS( REGEXMATCH(ax, "Mixed")*
REGEXMATCH(INDEX(C2:C, r), "Blend")*
REGEXMATCH(INDEX(C2:C, r), "Filter"), "BLEND-"&bx&"|FILTER-"&bx,
___________________________________________________________________________
REGEXMATCH(ax, "Mixed")*
NOT(REGEXMATCH(INDEX(C2:C, r), "Blend"))*
REGEXMATCH(INDEX(C2:C, r), "Filter"), "ESP-"&bx&"|FILTER-"&bx,
___________________________________________________________________________
REGEXMATCH(ax, "Mixed")*
NOT(REGEXMATCH(INDEX(C2:C, r), "Filter")), "BLEND-"&bx&"|ESP-"&bx,
___________________________________________________________________________
LEN(ax), SUBSTITUTE(ax&"-"&bx, "Espresso", "ESP"))
for better visualization, the IFS formula contains only 4 elements. each of these 4 elements acts as a switch - if there is a match x we get output y. for example let's dissect the first element...
REGEXMATCH(ax, "Mixed")*
REGEXMATCH(INDEX(C2:C, r), "Blend")*
REGEXMATCH(INDEX(C2:C, r), "Filter"), "BLEND-"&bx&"|FILTER-"&bx
there are 3x REGEXMATCHes multiplied by each other. whenever there is such multiplication in array formulae it translates as AND logic gate (if there would be + it would mean OR logic gate) eg.:
1 * 1 = 1
1 * 0 = 0
0 * 1 = 0
0 * 0 = 0
REGEXMATCH outputs TRUE or FALSE so if we get 3x TRUE the whole argument is considered as TRUE (because 1 * 1 * 1 = 1) so we proceed to output our first switch
therefore if B column contains Mixed and C column contains Blend and C column contains Filter then we output Blend-000|Filter-000 where 000 stands for a specific number determined from bx placeholder/formula and also you can notice the | (which btw stands for OR logic within the regex) but in this case, it's just a unique symbol to join stuff for REGEXMATCH. which REGEXMATCH is this for you may ask? ...this one:
so the output of IFS formula is the input for most outer REGEXMATCH and we check if the IFS output matches something within D1:O1 range. IF yes then output 1 otherwise output nothing. shortened:
IF(REGEXMATCH(IFS(...), "(?i)"&INDEX(D1:O1,,c), 1, )
(?i) in regex means "case insensitive". it is there just for safety reasons because regex is by default case sensitive.
and we reached the MAKEARRAY formula that creates an array of numbers across the whole range with height r and width c where output is the result of IF eg. either 1 or empty cell
everyone. I'm trying to do an iterative equation solver, where I put an equation then each iteration substitutes the X for a value then solves it. I'm having a hard time since the iterated function is considered a string. Any help is appreciated, thank you. The equation needs to be dynamic and be solved via iterations.
I tried calling the =substitute cell and end up having invalid data, since it reads as string.
try:
=BYROW(A9:A24, LAMBDA(ii, INDEX(QUERY(,
"select "®EXREPLACE(REGEXREPLACE(REGEXREPLACE(B2, "\^\d+", REPT("*x",
REGEXEXTRACT(B2, "\^(\d+)")-1)), "\(", "*("), "x", ii&"")), 2)))
logic:
caret ^ is not supported by QUERY so we first transform ^2 into an alternative. we know x^2 is equal to x*x so we extract that 2 and subtract 1 and REPT *x one time
next, we need to add multiplication as ()() needs to become ()*() same as 50x to 50*x
then we substitute x with value and evaluate the string with QUERY's SQL ## logic:
basically, we transform your:
-50(x)-1/2(-9.81)(x^2)+35
into:
-50*(0)-1/2*(-9.81)*(0*0)+35
-50*(1)-1/2*(-9.81)*(1*1)+35
-50*(2)-1/2*(-9.81)*(2*2)+35
etc.
UPDATE:
x^n where n is <1 are unachievable with REPT method and QUERY does not support roots so we can use a script to convert a text string into the formula
poor script example:
function onEdit(){
var sheet = SpreadsheetApp.getActiveSheet();
var source1= sheet.getRange('F7');
var source2= sheet.getRange('F8');
var formula1 = source1.getValue();
var formula2 = source2.getValue();
var target1 = sheet.getRange('B7');
var target2 = sheet.getRange('B8');
target1.setFormula(formula1);
target2.setFormula(formula2);
}
where F7 contains:
=BYROW(A7:A23, LAMBDA(i, "POW("&INDEX(QUERY(, "select "®EXREPLACE(
SUBSTITUTE(REGEXEXTRACT(B3, "(.+)\^"), ")(", ")*("), "x", i&"")), 2)&","&
REGEXEXTRACT(B3, "\^\((.+)\)")&")"))
I could be doing this completely wrong, or I could be on the right path, I have no idea! I'm trying to grade a decision based on 3 criteria. The grades are AAA-A and BBB-B, etc. but for now I just need AAA-A and can figure out the rest.
Essentially, we want Col. J to populate based on what Col.'s G-I say. In my head it's super easy but I want to automate this step.
So I start with col.I and see the pairing.. AAA-A results are any of these "G/G" "LG/G" "G/LG" or "R/R". If it is one of those 4 pairings then we start at AA grade.
Then I check col.G (it doesnt matter now if I check H or G first), and if G>=.5 we grade it higher at AAA, if its less than .5 then do nothing and keep it at AA.
Then I look at col. H (or G if we started at H) and if it is a "Y" we grade down from AA to A. or AAA to AA. But it is "N" do nothing.
What I have so far is attached. It technically works for 3/4 of these cells but that could be a coincidence. The results column(J) should be row3 - AA, row4 - AA, row5 - AAA, row6 - AA.
And for one additional test, imagine: col.g = .64, col.h = Y, col.i = G/G -- then we want AA as the result.
Definitely the hardest test I've had in excel/sheets. I appreciate the help! Thanks in advance!
Formula I tried:
=Ifs((or(I3="G/G",I3="LG/G",I3="G/LG",I3="R/R"),"AA", and(or(I3="G/G",I3="LG/G",I3="G/LG",I3="R/R"),G3>0.5),"AAA",H3="Y","A")
Data Sample:
G
H
I
J
3
-0.07
N
R/R
AA
4
-0.46
N
R/R
AA
5
0.64
N
G/G
AA
6
0.76
Y
LG/G
AA
As presented, your formula simply returns an error, and seems like a misinterpretation of how Ifs works. However, it suggest you're trying to Nest If statements. And, from your description, I think that makes sense.
Assuming that's a valid interpretation, the following does what you want.
(At least as far as AAA-A is concerned).
=If(or(I3="G/G",I3="LG/G",I3="G/LG",I3="R/R"),if(G3<0.5,"AA","AAA"),if(H3="Y","A","Not an A"))
The BBB-B logic would be the same (just nested in where "Not an A" is).
I want to look at each row in a frame and construct multiple columns for a new frame based on values in that row.
The final result should be a frame that has the columns of the original frame plus the new columns.
I have a solution but I wonder if there is a better one. I think the best way to explain the desired behavior is with an example. I'm using Deedle's titanic data set:
#r #"F:\aolney\research_projects\braintrust\code\QualtricsToR\packages\Deedle.1.2.3\lib\net40\Deedle.dll";;
#r #"F:\aolney\research_projects\braintrust\code\QualtricsToR\packages\FSharp.Charting.0.90.12\lib\net40\FSharp.Charting.dll";;
#r #"F:\aolney\research_projects\braintrust\code\QualtricsToR\packages\FSharp.Data.2.2.2\lib\net40\FSharp.Data.dll";;
open System
open FSharp.Data
open Deedle
open FSharp.Charting;;
#load #"F:\aolney\research_projects\braintrust\code\QualtricsToR\packages\FSharp.Charting.0.90.12\FSharp.Charting.fsx";;
#load #"F:\aolney\research_projects\braintrust\code\QualtricsToR\packages\Deedle.1.2.3\Deedle.fsx";;
let titanic = Frame.ReadCsv(#"C:\Users\aolne_000\Downloads\titanic.csv");;
This is what that frame looks like:
val titanic : Frame<int,string> =
PassengerId Survived Pclass Name Sex Age SibSp Parch Ticket Fare Cabin Embarked
0 -> 1 False 3 Braund, Mr. Owen Harris male 22 1 0 A/5 21171 7.25 S
1 -> 2 True 1 Cumings, Mrs. John Bradley (Florence Briggs Thayer) female 38 1 0 PC 17599 71.2833 C85 C
My approach grabs each row, uses some selection logic, and then returns a new row value as a dictionary. Then I use Deedle's expansion operation to convert the values in this dictionary to new columns.
titanic?test <- titanic |> Frame.mapRowValues( fun x -> if x.GetAs<int>("Pclass") > 1 then dict ["A", 1; "B", 2] else dict ["A", 2 ; "B", 1] );;
titanic |> Frame.expandCols ["test"];;
This gives the following new frame:
PassengerId Survived Pclass Name Sex Age SibSp Parch Ticket Fare Cabin Embarked test.A test.B
0 -> 1 False 3 Braund, Mr. Owen Harris male 22 1 0 A/5 21171 7.25 S 1 2
1 -> 2 True 1 Cumings, Mrs. John Bradley (Florence Briggs Thayer) female 38 1 0 PC 17599 71.2833 C85 C 2 1
Note the last two columns are test.A and test.B. Effectively this approach creates a new frame (A and B) and then joins the frame to the existing frame.
This is fine for my use case but it is probably confusing for others to read. Also it forces the prefix, e.g. "test", on the final columns which isn't highly desirable.
Is there a way to append the new values to the end of the row series represented in the code above by x?
I find your approach quite elegant and clever. Because the new series shares the index with the original frame, it is also going to be pretty fast. So, I think your solution may actually be better than the alternative option (but I have not measured this).
Anyway, the other option would be to return new rows from your Frame.mapRowValues call - so for each row, we return the original row together with the additional columns.
titanic
|> Frame.mapRowValues(fun x ->
let add =
if x.GetAs<int>("Pclass") > 1 then series ["A", box 1; "B", box 2]
else series ["A", box 2 ; "B", box 1]
Series.merge x add)
|> Frame.ofRows
I need your help again. I was wondering if it is possible to use lists:seq(from,to) within pattern matching? Below is the code that I am trying to achieve
product_selling_price_evaluate(lists:seq(1100,1190),standard_produce,Costprice) -> Costprice*10;
product_selling_price_evaluate(lists:seq(1200,1300),standard_produce,Costprice) -> Costprice*20;
product_selling_price_evaluate(lists:seq(1400,1500),standard_produce,Costprice) -> Costprice*30;
product_selling_price_evaluate(lists:seq(1600,1700),standard_produce,Costprice) -> 40*Costprice.
When I compile the code it gives me a illegal pattern error!
Example input would be
selling_price:product_selling_price_evaluate(1100,standard_produce,10).
and I want it to find the first one as a match and give the output as
100
Will lists:seq work with case?
Let me explain in a more simple way. I have the below cases
1100 to 1190 = Apples
1200 to 1300 = Oranges
1400 to 1500 = Bananas
1600 to 1700 = Berries
if I give the input as 1125 I want the output to be Apples. Again if I give the input as 1450, I want the output to be Bananas. I hope u guys understood, what am I trying to achieve!
If I interpret right what you are trying to achieve, what you probably are looking for are guards.
Something like this (untested):
product_selling_price_evaluate(N,standard_produce,Costprice) when N >= 10 andalso N <= 20 -> Costprice*10;
product_selling_price_evaluate(N,standard_produce,Costprice) when N >= 21 andalso N <= 30 -> Costprice*20;
[...]
You're not giving the desired input, your function is expecting a list([11001,1101, 1102,...,1189,1190]) as its first argument, where as you're giving a number i.e. 1100.
Guards can be comma-separated (,), it has the same meaning same as andalso.
product_selling_price_evaluate(N,standard_produce,Costprice)
when 10 =< N, N =< 20 -> Costprice*10;
product_selling_price_evaluate(N,standard_produce,Costprice)
when 21 =< N, N =< 30 -> Costprice*20;
...
<= is illegal here, use =< instead.