Forum Discussion
Anonymous
4 years agoNot applicable
Use Column header in calculated column
Hi All, I need help with the below requirement : This is the sample file data I am currently working on. It contains the below columns having some blank values. I need an additional calculated colu...
- 4 years ago
Thank you for the sample data. Note that it has a lot of extra spaces so the following code may need some adjustments once you cleaned the data up.
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8k0sLkktUtJRMgRiR0cQwwDEVFCK1UGSNQJiJyewuI5ScKAPqqwxVMLQAKQuIL88tUjByROsJji/tCg5FShqAlcDUh0c7BmMKm8KxM7OUEVotpsBsYsLWLMJWLMjUHMsAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Filename = _t, #" Col A" = _t, #" Col B" = _t, #" Col C" = _t, #" Col D" = _t]), CN =Table.ColumnNames(Source), #"Added Custom" = Table.AddColumn(Source, "Output Col", (k)=> let l = List.Generate(()=>[x=1,y=""], each [x] < List.Count(CN), each [x=[x]+1, y=[y] & (if Record.Field(k,CN{[x]}) > " " then "" else ", " & CN{[x]})], each [y] & (if Record.Field(k,CN{[x]}) > " " then "" else ", " & CN{[x]}) ), m = try Record.Field(k,CN{0}) & "/" & Text.Range(l{List.Count(CN)-2},2) otherwise null in m ) in #"Added Custom"How to use this code: Create a new Blank Query. Click on "Advanced Editor". Replace the code in the window with the code provided here. Click "Done".
Anonymous
4 years agoNot applicable
This is the sample data, columns can be more in future.
| Filename | Col A | Col B | Col C | Col D | Output Col |
| Master | 1 | AA | 101 | Master/Col D | |
| Master | 2 | BB | SQL | Master/Col C | |
| Master | 3 | 102 | Power BI | Master/Col B | |
| Source | 4 | 103 | SSIS | Source/Col B | |
| Source | 5 | CC | Source/Col C, Col D | ||
| Master | 6 | DD | 104 | SSAS | BLANK() |
Basically, I am looking for a dynamic solution that if any column in the table is blank that Column name has to be spotted in the output column. One shouldn't specifically mention any column name to check if it is blank or not i.e., the isblank operation should be performed row-wise.
I hope it helps lbendlin
- lbendlin4 years agoSuper User
Thank you for the sample data. Note that it has a lot of extra spaces so the following code may need some adjustments once you cleaned the data up.
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8k0sLkktUtJRMgRiR0cQwwDEVFCK1UGSNQJiJyewuI5ScKAPqqwxVMLQAKQuIL88tUjByROsJji/tCg5FShqAlcDUh0c7BmMKm8KxM7OUEVotpsBsYsLWLMJWLMjUHMsAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Filename = _t, #" Col A" = _t, #" Col B" = _t, #" Col C" = _t, #" Col D" = _t]), CN =Table.ColumnNames(Source), #"Added Custom" = Table.AddColumn(Source, "Output Col", (k)=> let l = List.Generate(()=>[x=1,y=""], each [x] < List.Count(CN), each [x=[x]+1, y=[y] & (if Record.Field(k,CN{[x]}) > " " then "" else ", " & CN{[x]})], each [y] & (if Record.Field(k,CN{[x]}) > " " then "" else ", " & CN{[x]}) ), m = try Record.Field(k,CN{0}) & "/" & Text.Range(l{List.Count(CN)-2},2) otherwise null in m ) in #"Added Custom"How to use this code: Create a new Blank Query. Click on "Advanced Editor". Replace the code in the window with the code provided here. Click "Done".