Modify query function so it can work as an arrayformula in Google Sheets - google-sheets-formula

How do I modify this equation so I can use it with an array function instead of dragging it down.
SUBSTITUTE(JOIN(", ", UNIQUE(QUERY(A:D,"SELECT B WHERE C = '"&G2&"'"))), ", , ", "")
Explanation of the equation:
Have a function is used to extract and concatenate unique values from column B of a sheet named A:D, where the values in column C match a specific criteria. The function is made up of several parts:
It uses the QUERY function to extract all values from column B of sheet A:D where the values in column C match the specific criteria in G.
UNIQUE removes any duplicate values from previous step.
JOIN to concatenate into a single string separated by a comma to returns a string of unique values that match the criteria
SUBSTITUTE to replace occurrences of ", , " with an empty string.

can you try:
=BYROW(G2:G,LAMBDA(gx,IF(gx="",,TEXTJOIN(", ",1,IFNA(UNIQUE(FILTER(B:B,C:C=gx)))))))

Related

Power Query - How to extract after delimiter

I have info in a column, that needs to be split into two columns. It can be shown like:
1,000,1111,000 - what we should see is 1,000,111 - 1,000 - or
1,1111,100 - what we should see is 1,111 - 1,100
etc.
I need to separate these columns. I assume the conditions should be "If there are four digits after a comma, separate at this point, into two columns.
It's not immediately obvious how I should fix this. Any thoughts?
EDIT: essentially, the criteria is: If the 4th character after any comma is not another comma, move the 4th character onward onto another column.
This query splits the text string into a list, using its commas as delimiters; then looks at each list entry to find the one that is greater than 3 digits; then inserts a semicolon after the 3rd digit of that entry that is longer than 3 digits; then recombines the list into a text string, with commas; then splits that recombined string into two columns, using the semicolon as the delimiter.
let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
Custom1 = Table.TransformColumns(Source, {"Column1", each Text.Combine(List.Transform(Text.Split(_,","), each if Text.Length(_) > 3 then Text.Insert(_,3,";") else _),",")}),
#"Split Column by Delimiter" = Table.SplitColumn(Custom1, "Column1", Splitter.SplitTextByDelimiter(";", QuoteStyle.Csv), {"Column1.1", "Column1.2"})
in
#"Split Column by Delimiter"
The table I used to develop/test this is simply this table, which I named Table1:
The query result looks like this:

SSRS [Sort Alphanumerically]: How to sort a specific column in a report to be [A-Z] & [ASC]

I have a field set that contains bill numbers and I want to sort them first alphabetically then numerically.
For instance I have a column "Bills" that has the following sequence of bills.
- HB200
- SB60
- HB67
Desired outcome is below
- HB67
- HB200
- SB60
How can I use sorting in SSRS Group Properties to have the field sort from [A-Z] & [1 - 1000....]
This should be doable by adding just 2 separate Sort options in the group properties. To test this, I created a simple dataset using your examples.
CREATE TABLE #temp (Bills VARCHAR(20))
INSERT INTO #temp(Bills)
VALUES ('HB200'),('SB60'),('HB67')
SELECT * FROM #temp
Next, I added a matrix with a single row and a single column for my Bills field with a row group.
In the group properties, my sorting options are set up like this:
So to get this working, my theory was that you needed to isolate the numeric characters from the non-numeric characters and use each in their own sort option. To do this, I used the relatively unknown Regex Replace function in SSRS.
This expression gets only the non-numeric characters and is used in the top sorting option:
=System.Text.RegularExpressions.Regex.Replace(Fields!Bills.Value, "[0-9]", "")
While this expression isolates the numeric characters:
=System.Text.RegularExpressions.Regex.Replace(Fields!Bills.Value, "[^0-9]", "")
With these sorting options, my results match what you expect to happen.
In the sort expression for your tablix/table which is displaying the dataset, set the sort to something like:
=IIF(Fields!Bills.Value = "HB67", 1, IIF(Fields!Bills.Value = "HB200", 2, IIF(Fields!Bills.Value = "SB600", 3, 4)))
Then when you sort A-Z, it'll sort by the number given to it in the sort expression.
This is only a solution if you don't have hundreds of values, as this can become quite tedious to create if there's hundreds of possible conditions.

replace multiple words in string with specific words from list

How can I, using M-language, replace specific words in a string with other specific words that are specified in a table?
See my example data:
Source code:
let
someTable = Table.FromColumns({{"aa &bb &cc dd","&ee ff &gg hh &ii"}, {Table.FromColumns({{"&bb","&cc"}, {"ReplacementForbb", "ccReplacement"}},{"StringToFind", "ReplaceWith"}), Table.FromColumns({{"&ee", "&gg","&ii"}, {"OtherReplacementForee", "SomeReplacementForgg", "Replacingii"}},{"StringToFind", "ReplaceWith"})}, {"aa ReplacementForbb ccReplacement dd","OtherReplacementForee ff SomeReplacementForgg hh Replacingii"}},{"OriginalString", "Replacements", "WantedResult"})
in
someTable
This is a neat question. You can do this with some table and list M functions as a custom column like this:
= Text.Combine(
List.ReplaceMatchingItems(
Text.Split([OriginalString], " "),
List.Transform(Table.ToList([Replacements]),
each Text.Split(_,",")
)
),
" ")
I'll walk through how this works using the first row as an example.
The [OriginalString] is "aa &bb &cc dd" and we use Text.Split to convert it to a list.
"aa &bb &cc dd" --Text.Split--> {"aa", "&bb", "&cc", "dd"}
Now we need to work on the [Replacements] table and convert it into a list of lists. It starts out:
StringToFind ReplaceWith
------------------------------
&bb ReplacementForbb
&bb ccReplacement
Using Table.ToList this becomes a two element list (since the table had two rows).
{"&bb,ReplacementForbb","&cc,ccReplacement"}
Using Text.Split on the comma, we can transform each element into a list to get
{{"&bb","ReplacementForbb"},{"&cc","ccReplacement"}}
which is the form we need for the List.ReplaceMatchingItems function.
List.ReplaceMatchingItems(
{"aa", "&bb", "&cc", "dd"},
{{"&bb","ReplacementForbb"},{"&cc","ccReplacement"}}
)
This does the replacement and returns the list
{"aa","ReplacementForbb","ccReplacement","dd"}
Finally, we use Text.Combine to concatenate the list above into a single string.
"aa ReplacementForbb ccReplacement dd"

How to replace _A_&_B_ using gsub in R

I am trying to join two columns containing company names from two distinct data tables on R. In one column I have the pattern _A_&_B_ where A and B can be any letters. I would like to get rid of those two letters i.e letter of length 1 surrounded by _
So if I have John_K_&_E_Scott I would like to have John__&__Scott as I can remove the punctuation. I have tried the below
names[, JOINING_ID := gsub("[A-Za-z]_&_[A-Za-z]\\w", "", JOINING_ID)]
But this transforms John_A_&_ BOYS_ in John__&_ OYS_ which is not what I want.
Use the following regex pattern:
_[[:alpha:]]_&_[[:alpha:]]_
and replace with __&__. See the regex demo. It won't match strings like John_A_&_BOYS_ and thus there won't be issues like the one you are having.
Note that [[:alpha:]] matches any letter.
R usage:
gsub("_[[:alpha:]]_&_[[:alpha:]]_", "__&__", JOINING_ID)
Or, if you only expect 1 match per string, use sub:
sub("_[[:alpha:]]_&_[[:alpha:]]_", "__&__", JOINING_ID)

grid filter in foxpro

I have a grid on a form that displays some columns from a dbf table and a textbox.
I want to search the value displayed in the textbox over all columns from a dbf table. Some fields are numeric and other are character
If I want to find a number, should search all record that contain that number in all columns, no matter the column type.
If I want to search a substring should give me all record that contain that substring.
SET FILTER TO ALLTRIM(ThisForm.Text1.Value) $Content or ALLTRIM(val(ThisForm.Text1.Value)) $registrationNumber or ALLTRIM(ThisForm.Text1.Value) $holderNo
Your approach with the "$" wildcard "contains" approach appears to be ok. However, your attempt via allt( val( )) would fail as you cant trim a numeric value, it would have to be pre-converted to a string.
Now, that said, you could shorten your query by just doing a $ against a concatenation of ALL columns something like (assuming your registration number is a numeric field)...
set filter to ALLTRIM(ThisForm.Text1.Value) ;
$ ( Content +"," +str(registrationNumber) +," + holderNo )
if you have dates or date/time fields you could do DTOC( dateField ) or TTOC( dateTimeField). So, by building a single string of all values, you dont have to explicitly repeat the OR condition repeatedly.
You could do something like:
select curGrid
scan
lcRow = transform(field1) + transform(field2) ... + transform(lastfield)
if lcSearchValue $ lcRow
DoWhatever()
endif
endscan
This leverages the fact that transform() will give a string representation of any data type.

Resources