I'm trying to create multiple IF in a single cell so if the cell states "Critical", then adjacent cells should state "response required within 24hrs". If the cell states "Medium", the adjacent cell should state "response required within 48hrs". If it states "Low", then the adjacent should state "Response required after other priorities are address"... how do I create that formula?
like this:
=IF(A1="Critical"; "response required within 24hrs";
IF(A1="Medium"; "response required within 48hrs";
IF(A1="Low"; "response required after other priorites are addresse"; )))
for array like this:
=ARRAYFORMULA(
IF(A1:A10="Critical"; "response required within 24hrs";
IF(A1:A10="Medium"; "response required within 48hrs";
IF(A1:A10="Low"; "response required after other priorites are addresse"; ))))
It will be easier if you use a SWITCH statement instead of multiple chained IFs.
The generic formula looks like: SWITCH(expression, case1, value1, [case2_or_default, …], [value2, …])
So for your special use case it will look like this:
=SWITCH([CELL-TO-COMPARE],"Critical","response required within 24hrs","Medium","response required within 48hrs","Low","Response required after other priorites are addresse")
Have fun, cheers
Related
How can I remove a large number of columns by name based on a pattern?
A data set exported from Jira has a ton of extra columns that I've no interest in. 400 Log entries, 50 Comments, dozens of links or attachments. Problem is that they get random numbers assigned which means that removing them with hardcoded column names will not work. That would look like this and break as the numbers change:
= Table.RemoveColumns(#"Previous Step",{"Watchers", "Watchers_10", "Watchers_11", "Watchers_12", "Watchers_13", "Watchers_14", "Watchers_15", "Watchers_16", "Watchers_17", "Watchers_18", "Watchers_19", "Watchers_20", "Watchers_21", "Watchers_22", "Watchers_23", "Watchers_24", "Watchers_25", "Watchers_26", "Watchers_27", "Watchers_28", "Log Work", "Log Work_29", "Log Work_30", "Log Work_31", "Log Work_32", ...
How can I remove a large number of columns by using a pattern in the name? i.e. remove all "Log Work" columns.
The best way I've found is to use List.FindText on Table.ColumnNames to get a list of column names dynamically based on target string:
= Table.RemoveColumns(#"Previous Step", List.FindText(Table.ColumnNames(#"Previous Step"), "Log Work")
This works by first grabbing the full list of Column Names and keeping only the ones that match the search string. That's then sent to RemoveColumns as normal.
Limitation appears to be that FindText doesn't offer complex pattern matching.
Of course, when you want to remove a lot of different patterns, having individual steps isn't very interesting. A way to combine this is to use List.Combine to join the resulting column names together.
That becomes:
= Table.RemoveColumns(L, List.Combine({ List.FindText(Table.ColumnNames(L), "Watchers_"), List.FindText(Table.ColumnNames(L), "Log Work"), List.FindText(Table.ColumnNames(L), "Comment"), List.FindText(Table.ColumnNames(L), "issue link"), List.FindText(Table.ColumnNames(L), "Attachment")} ))
SO what's actually written there is:
Table.RemoveColumns(PreviousStep, List.Combine({ foundList1, foundlist2, ... }))
Note the { } that signifies a list! You need to use this as List.Combine only accepts a single argument which is itself already a List of lists. And the Combine call is required here.
Also note the L here instead of #"Previous Step". That's used to make the entire thing more readable. Achieved by inserting a step named "L" that just has = #"Promoted Headers".
This allows relatively maintainable removal of multiple columns by name, but it's far from perfect.
I am using ARRAYFORMULA with multiple conditions using SUMIF concatenating the conditions using & and it works. Now I would like to use similarly this idea for a special condition indicating to consider all values using a wildcard ("ALL") for a given column, but it doesn't work.
Here is my example:
On I2if have the following formula:
=ARRAYFORMULA(if(not(ISBLANK(H2:H)),sumif(B2:B & C2:C & D2:D & year(E2:E),
if($G$2="ALL",B2:B,$G$2) & if($G$4="ALL",C2:C,$G$4) & if($G$6="ALL",D2:D,$G$6) &
H2:H,A2:A),))
and it works, when I enter specific values, but when I use my wildcard: ALL indicating that for a given column/criteria all values should be taken into consideration, it doesn't work as expected. The scenario should consider that all criteria can be labeled as ALLin such case it will provide the sum of NUM per year.
Here is my testing sample in Google Spreadsheet:
https://docs.google.com/spreadsheets/d/1c28KRQWgPCEdzVvwvXFOQ3Y13MBDjpEgKdfoLipFAOk/edit?usp=sharing
Notes:
I was able to get a solution for that using SUMPRODUCT but this function doesn't get expanded with ARRAYFORMULA
In my real example I have more conditions, so I am looking for a solution that escalates having more conditions
use:
=QUERY(QUERY(FILTER(A2:E,
IF(G2="All", B2:B<>"×", B2:B=G2),
IF(G4="All", C2:C<>"×", C2:C=G4),
IF(G6="All", D2:D<>"×", D2:D=G6)),
"select year(Col5),sum(Col1)
where Col1 is not null
group by year(Col5)"),
"offset 1", 0)
I've a scenario where 10K+ regular expressions are stored in a table along with various other columns and this needs to be joined against an incoming dataset. Initially I was using "spark sql rlike" method as below and it was able to hold the load until incoming record counts were less than 50K
PS: The regular expression reference data is a broadcasted dataset.
dataset.join(regexDataset.value, expr("input_column rlike regular_exp_column")
Then I wrote a custom UDF to transform them using Scala native regex search as below,
Below val collects the reference data as Array of tuples.
val regexPreCalcArray: Array[(Int, Regex)] = {
regexDataset.value
.select( "col_1", "regex_column")
.collect
.map(row => (row.get(0).asInstanceOf[Int],row.get(1).toString.r))
}
Implementation of Regex matching UDF,
def findMatchingPatterns(regexDSArray: Array[(Int,Regex)]): UserDefinedFunction = {
udf((input_column: String) => {
for {
text <- Option(input_column)
matches = regexDSArray.filter(regexDSValue => if (regexDSValue._2.findFirstIn(text).isEmpty) false else true)
if matches.nonEmpty
} yield matches.map(x => x._1).min
}, IntegerType)
}
Joins are done as below, where a unique ID from reference data will be returned from UDF in case of multiple regex matches and joined against reference data using unique ID to retrieve other columns needed for result,
dataset.withColumn("min_unique_id", findMatchingPatterns(regexPreCalcArray)($"input_column"))
.join(regexDataset.value, $"min_unique_id" === $"unique_id" , "left")
But this too gets very slow with skew in execution [1 executor task runs for a very long time] when record count increases above 1M. Spark suggests not to use UDF as it would degrade the performance, any other best practises I should apply here or if there's a better API for Scala regex match than what I've written here? or any suggestions to do this efficiently would be very helpful.
I'm trying to return a value in Google sheets.
This is done using an Index Match as follows, which does work:
=iferror(index(Data!B:B, match(B5339,Data!G:G,0)),"Not Found")
I'd now like to expand this, so that if this first test fails, try looking up that same data in another sheet....
=iferror(if(index(Data!B:B, match(B5340,Data!G:G,0),if(index(HeadOfficeLeads!B:B, match(B5340,HeadOfficeLeads!A:A,0))))),"Not found")
This outputs the fail msg of "Not Found".
However, although the first test is indeed false, the second test is true (this second data set does in fact hold a match).
NB - the data containing this correct match on the 2nd sheet is created by a UNIQUE ( FILTER, FWIW....
For some reason, it doesnt look like the second IF statement is being run - and the whole thing doesnt work, giving the error "Wrong number of arguments".
I have a feeling the argument issue is that the first test doesnt have an "if false" clause - but believe the "IFERROR" parent should handle this?
If not, where would I put the "if false clause" for the IF's?
You don't need any if, because iferror already contains an if statement in its logic (as its name suggests). Here is an example of nested iferror statements, simplified for clarity:
=iferror(match("a", A1:A5, 0), iferror(match("a", B1:B5", 0), "not found"))
This will return the position of "a" in column A, if it's there; otherwise, it will return its position in column B if it's there, otherwise it returns "not found".
Works the same with index or anything else around match function.
I have written the following function in google sheets in order to add "ID" to a column:
=if(and(E2>43%, E2<57%, C2=2016), "ID", " ")
I would like to add another logical operator, OR, to this. I would like to add "ID" if the following conditions are met, OR if the conditions above are met:
E2 >57%, C2=2016, J2=""
Column J has names written in it. What I'm trying to say with J2="" is that the space is not blank. I don't care about what the name is, just that there is text written. I wrote this but it doesn't work:
=if(or(and(E2>43%, E2<57%, C2=2016),AND(E2>57%, C2=2016, J2=""), "ID", " "))
Thanks for your help!
Try this one:
=IF(or(and(B1>43%, B1<57%, A1=2016),and(B1 >57%, A1=2016,istext(E1))), "ID",)