I need function what will return currency type of cell property. Is it possible?
I found only =TYPE(cell) method what return only data type (number, string etc)
there isn't such a function. you will need to try something like:
=INDEX(IFNA(VLOOKUP(REGEXREPLACE(TO_TEXT(A1:A3), "[0-9, ]", ),
{"$", "USD"; "€", "EUR"; "zł", "PLN"}, 2, 0)))
also, you may want to see: https://stackoverflow.com/questions/73767719/locale-differences-in-google-sheets-documentation-missing-pages
Related
I'm trying to add a custom column to combine values of 2 columns (Col3 and Col4) with the result of a custom function fnMyFunction() in this way
#"Added Custom" = Table.AddColumn(#"Previous Step", "Custom Column",
each
Text.Combine(
{
[Col3],
[Col4],
fnMyFunction([Col5],[Col6])
}
)),
I'm getting this error when function handles null values
Expression.Error: We cannot convert the value null to type Text.
Details:
Value=
Type=[Type]
The function fnMyFunction is like this:
(input1 as text, input2 as text)=>
let
Inputs = {input1, input2},
SplitAndZip = List.Zip(List.Transform(Inputs, each Text.ToList(_))),
OtherStep
...
..
LastStep
in
LastStep
I've tried to add the if else in Input step in order to get empty as output for the function but doesn't work
(input1 as text, input2 as text)=>
let
Inputs = if input1 <> null then {input1, input2} else {"",""}, //Added "if else" here
SplitAndZip = List.Zip(List.Transform(Inputs, each Text.ToList(_))),
OtherSteps
...
..
LastStep
in
LastStep
How can be fix this?
Change your function definition to be the following:
(optional input1 as text, optional input2 as text)=>
PQ has a null-coalesce operator ??. Try this:
Inputs = {input1 ?? "", input2 ?? ""}
edit from the future - #2 is wrong. My bad. Still, read Ben's guide. It's the best PQ text-book there is.
Once you fix the fn, each... Combine([col3],[col4]..) will break because you forgot to _ before [col3] and [col4]. each..._ is syntactic sugar for a single-argument function (eating a whole row, in this case). See here: https://bengribaudo.com/blog/2017/12/08/4270/power-query-m-primer-part3-functions-function-values-passing-returning-defining-inline-recursion
Use
each try Text.Combine() otherwise ""
Inside my data flow pipeline I would like to add a derived column and its datatype is array. I would like to split the existing column with 1000 characters without breaking words. I think we can use regexSplit,
regexSplit(<string to split> : string, <regex expression> : string) => array
But I do not know which regular expression I can use for split the existing column without breaking words.
Please help me to figure it out.
I created a workaround for this and it works fine for me.
filter(split(regexReplace(regexReplace(text, `[\t\n\r]`, ``), `(.{1,1000})(?:\s|$)`, `$1~~`), '~~'), #item !="")
I think, we have a better solution than this.
I wouldn't use a regex for this, but a truncating function like this one, courtesy of TimS:
public static string TruncateAtWord(this string input, int length)
{
if (input == null || input.Length < length)
return input;
int iNextSpace = input.LastIndexOf(" ", length, StringComparison.Ordinal);
return string.Format("{0}…", input.Substring(0, (iNextSpace > 0) ? iNextSpace : length).Trim());
}
Translated into expression functions it would look something* like this.
substring(Input, 1, iif(locate(Input, ' ', 1000) > 0, locate(Input, ' ', 1000) , length(Input)) )
Since you don't have a lastIndexOf available as an expression function, you would have to default to locate, which means that this expression truncates the string at the first space after the 1000th character.
*I don't have an environment where I can test this.
I have a Google spreadsheet with 2 columns.
Each cell of the first one contains JSON data, like this:
{
"name":"Love",
"age":56
},
{
"name":"You",
"age":42
}
Then I want a second column that would, using a formula, extract every value of name and string it like this:
Love,You
Right now I am using this formula:
=REGEXEXTRACT(A1, CONCATENER(CHAR(34),"name",CHAR(34),":",CHAR(34),"([^",CHAR(34),"]+)",CHAR(34),","))
The RegEx expresion being "name":"([^"]+)",
The problem being that it currently only returns the first occurence, like this:
Love
(Also, I don't know how many occurences of "name" there are. Could be anywhere from 0 to around 20.)
Is it even possible to achieve what I want?
Thank you so much for reading!
EDIT:
My JSON data starts with:
{
"time":4,
"annotations":[
{
Then in the middle, something like this:
{
"name":"Love",
"age":56
},
{
"name":"You",
"age":42
}
and ends with:
],
"topEntities":[
{
"id":247120,
"score":0.12561166,
"uri":"http://en.wikipedia.org/wiki/Revenue"
},
{
"id":31512491,
"score":0.12504959,
"uri":"http://en.wikipedia.org/wiki/Wii_U"
}
],
"lang":"en",
"langConfidence":1.0,
"timestamp":"2020-05-22T12:17:47.380"
}
Since your text is basically a JSON string, you may parse all name fields from it using the following custom function:
function ExtractNamesFromJSON(input) {
var obj = JSON.parse("[" + input + "]");
var results = obj.map((x) => x["name"])
return results.join(",")
}
Then use it as =ExtractNamesFromJSON(C1).
If you need a regex, use a similar approach:
function ExtractAllRegex(input, pattern,groupId,separator) {
return Array.from(input.matchAll(new RegExp(pattern,'g')), x=>x[groupId]).join(separator);
}
Then use it as =ExtractAllRegex(C1, """name"":""([^""]+)""",1,",").
Note:
input - current cell value
pattern - regex pattern
groupId - Capturing group ID you want to extract
separator - text used to join the matched results.
I am having error when uploading my website on heroku as having default values in function.
Until now I have used default value lots of times and they are in 50000 column javascript file and I cant really find all of them.
So I tried to find all functions with default values in sublime using regex.
I tried this regular expression.
function.*\(.*\=.*\)
But it's finding this kind of string(which is not default value function).
Function(e)) return Q.grep(t, function(t, i) { return !!e.call(t, i, t) !== n })
Sample function to be searched
var abc = function(x , y = 1)
function abc(x , y = 1)
Please help, I am new to regular expression and it's really difficult to find answer.
Try this regex function[a-zA-Z ]*\([a-zA-Z \,]+[a-zA-Z ]*[=]. It will match the functions with default parameters regardless of number of parameters. I hope this helped.
function\([^)]+\)
and take refernce from this:
Regular expression to find all function calls with parameters in VS2010
Try this one function[\s\w]*\([\w\s\d,]*[\w\s]+=[\w\d\s'",]*\). Default value may be string, and also function may have name:
var abc = function some_name (x , y = 1, z = "string", z_z) { var = 1
I am trying to parse a long string with comma-separated values such as "lat,long,distance,,elevation". String is actually quite long and I need to fetch each value and save the fetched values in different columns in dynamodb. I am using dyamodbv2 rule. Functions I found that could be useful were substring(String, Int [, Int]), length(String), indexof(String, String) and get().
For example I get data like this:
{
LOCATION_DATA: "lat,long,distance,,elevation"
}
Here is what I have done so far,
//first value - 0 to next comma
substring(LOCATION_DATA, 0, indexof(LOCATION_DATA, ',')) as latitude,
//second value - substring starting from last substring to next comma
substring(substring(LOCATION_DATA, indexof(LOCATION_DATA, ',') +1 ) ,
0,
indexof(substring(LOCATION_DATA, indexof(LOCATION_DATA, ',') +1 ), ',')
) as longitude,
...
But this gets too verbose and moving to next comma-separated value increasingly difficult. Is there a way to convert comma-separated values to array and then fetch them with get(0), get(1).. ? I have to fetch around 20 fields this way!
Also, the values can be of varying length, and some fields can be empty, such as value between "distance,,elevation" in example strings. These empty values can be ignored.
As far as I now, there is no way I can store and create custom functions, or use any other function than provided in http://docs.aws.amazon.com/iot/latest/developerguide/iot-sql-functions.html.
In rails, you can convert a string to array based on a separator
Example
LOCATION_DATA = "lat,long,distance,,elevation"
myarray = LOCATION_DATA.split(',')
Then you can use
myarray[0]="lat"
myarray[1]="long"
myarray[2]="distance"
myarray[3]=""
myarray[4]="elevation"
You can also convert these strings to integer or float as:
myarray[0].to_i
myarray[2].to_f
Hope This Helps