I am dealing with a column which is having Text Value mixed with Table data.
Table value
I would like to operate on this column by
if value = Table : aggregate the Table by combining the value with a comma separator
if value = : keep the original value
The result would be
I use this function to aggregate the value for Table, but I got an error when the value is a text
= Table.AggregateTableColumn(#"Lignes filtrées1", "value.1", {{"Element:Text", each Text.Combine(List.Transform(_, (x) => Text.From(x)), ", "), "Desired Result"}})
Would you have some tips to help me with this problem ?
Thanks in advance
It is hard to tell what you have in your table
As an example if the embedded table looked like this, with a single column
then you could add a column like
#"Added Custom" = Table.AddColumn(#"PriorStepName", "Custom", each try Text.Combine([Column1][TableColumn1],",") otherwise [Column1])
and get
If your table is more complicated you'd probably have to unpivot it first or otherwise give us a hint how to transform it into a single cell
Related
I have an unpivoted table in the Power BI Query with +20 columns and +10000 rows.
The first columns are related to KPI name, month, and other data of interest. The columns after are the columns that contain the actual values I want to display.
Some rows have the KPI description (name, month, etc.) but do NOT any values in the rest of the columns ("NULL").
Is there a way to remove these rows? Remove whenever all the values of the rest of the columns are "NULL". (First columns will never be empty)
Thank you!!
I'm still a beginner in this Power BI world :)
If the other columns are always nulls together, then just pick one of those columns and use the arrow atop the column to remove the tick mark from [ ] null and filter it out
= Table.SelectRows(#"PriorStepName", each (Total number of shipments inbound] <> null)
If you have to check that every column except certain columns have nulls, then you could do this, which counts the number of nulls on each row. Then filter that column for proper number of nulls using the drop down atop that new column
= Table.AddColumn(#"PriorStepName", "Count", each List.NonNullCount(Record.ToList(_)))
Similarly you could count the number of null columns excluding the first X columns (here the first 2 columns) then filter that column
= Table.AddColumn(#"PriorStepName", "Count", each List.NonNullCount(List.Skip(Record.ToList(_),2)))
Hello I need to multiply two columns in a new column in Power Query where the columns can change name but not position. So for example I want to multiply the second column in a table with the fourth column in the same table independently and want to be able to change name on the table headers and the code should still work
Table.ColumnNames(Source){1} would be the name of the 2nd column
Table.ColumnNames(Source){3} would be the name of the 4th column
You can then wrap it with Record.Field (_,x) to get the value
so the value in the second column would be
Record.Field (_,Table.ColumnNames(Source){1})
So the code below would create a new column named Mult that multiplies columns 2 and 4 without knowing their column names
let Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Added Custom" = Table.AddColumn(Source, "Mult", each
Record.Field (_,Table.ColumnNames(Source){1}) *
Record.Field (_,Table.ColumnNames(Source){3}) )
in #"Added Custom"
How can I use a column value as a column name. I've tried this:
SELECT TableX.(
SELECT OdTable.columnamecell
from OdTable
where 1 =1
AND OdTable.KeyValue = TableX.SomeValue
) as MyValue
,TableX.OtherValue as OtherValue
, TableX.SomeValue
from TableX
WHERE 1 = 1
Or to say it another way: Can I use a table column value as a column name for another query or sub-query?
To clarify: The table: OdTable has a column with values that are the column name in another table.
No, and Yes. You can't do this with "standard" SQL; all table and column names must be known, as literals, when the query is compiled; they can't be provided at runtime. What you want is called "dynamic SQL"; sometimes it is the only solution to a problem, but most of the time it is used when it is not necessary. It has several disadvantages (security risk, performance penalty, difficulty to maintain, ...)
I am loading data from a csv file into a table using sqlldr. There is one column which is not present in every row of the csv file. The data needed to populate this column is present in one of the other columns of the row. I need to split (split(.) )that column's data and populate into that column.
Like:-
column1:- abc.xyz.n
So the unknown column(column2) should be
column2:- xyz
Also, there is another column which is present in the row but it's not what I want to input into the table. It is also needed to be populated from column1. But there are around 50 if-else cases in that. Is decode preferable to do this?
column1:- abc.xyz.n
Then,
column2:- hi if(column1 has 'abc')
if(column1 has 'abd' then 'hello')
like this there are around 50 if-else cases.
Thanks for help.
For the first part of your question, define the column1 data in the control file as BOUNDFILLER with a name that does not match a table column name which tells sqlldr to remember it but don't use it. If you need to load it into a column, use the column name plus the remembered name. For column2, use the remembered BOUNDFILLER name in an expression where it returns the part you need (in this case the 2nd field, allowing for NULLs):
x boundfiller,
column1 EXPRESSION ":x",
column2 EXPRESSION "REGEXP_SUBSTR(:x, '(.*?)(\\.|$)', 1, 2, NULL, 1)"
Note the double backslash is needed else it gets removed as it gets passed to the regex engine from sqlldr and the regex pattern is altered incorrectly. A quirk I guess.
Anyway after this column1 ends up with "abc.xyz.n" and column2 gets "xyz".
For the second part of your question, you could use an expression as already shown but call a custom function you create where you pass the extracted value and it would return the searched value from a lookup table. You certainly don't want to hardcode your 50 lookup values. You could do the same thing basically in a table level trigger too. Note I show a select statement for an example only but this should be encapsulated in a function for reusability and maintainability:
Just to show you can do it:
col2 EXPRESSION "(select 'hello' from dual where REGEXP_SUBSTR(:x, '(.*?)(\\.|$)', 1, 2, NULL, 1) = 'xyz')"
The right way:
col2 EXPRESSION "(myschema.mylookupfunc(REGEXP_SUBSTR(:x, '(.*?)(\\.|$)', 1, 2, NULL, 1)))"
mylookupfunc returns the result of looking up 'xyz' in the lookup table, i.e. 'hello' as per your example.
I want to remove a piece of a string from a particular table's column. The string I wish to remove is the &expires and everything after it but leave everything before the &expires the same. Is there a way to accomplish with the update statement or is a stored procedure needed?
Table column value is:
Starting Value: DAABq3J65GvwBABbWdkFOnpCj2mEA1lMonZBZADcTYJR6QuLPUlfZBtMyoEl4x2JXQ49cOzjZAStQxWNOgrurtnMNIw04bmOcQ4SsrjuPKH4AZBBBAf8ZBjWhs8BM52aC0OpnPGzjm6V2x50qk6wboT&expires=5183999
Desired Ending Value:
DAABq3J65GvwBABbWdkFOnpCj2mEA1lMonZBZADcTYJR6QuLPUlfZBtMyoEl4x2JXQ49cOzjZAStQxWNOgrurtnMNIw04bmOcQ4SsrjuPKH4AZBBBAf8ZBjWhs8BM52aC0OpnPGzjm6V2x50qk6wboT
update table set column = regexp_replace(column, '&'||'expires=.*$')