Forum Discussion
Power Query - get column name
AlexisOlson Thank you for your help.
It all looks good, but one thing I would like to change. Is there a way to avoid handwriting "Job Name"?
In my example (below), I am already passing the column name as a Parameter. Can we somehow use this variable to be used automatically in the output (FinalText)?
As an example, If my parameter (MyColumn) is Job Name I want the first argument of Text.Combine to be referenced as JobName, but in the below function it is taking the cell (row) value, instead of the MyColumn.
(MyColumn) as text =>
let
Source = Text.Length(MyColumn),
NewSource = Number.ToText(Source),
FinalText = Text.Combine({MyColumn,NewSource}," ")
in FinalText
- AlexisOlson3 years agoSuper User
I don't quite follow. You need to specify "Job Name" once so the function knows what column you want to read text lengths from. There's no other place in what I suggested that has "Job Name" hard coded and the output is what you specified.
Maybe if I rewrite it a bit more like your code it will be slightly clearer?
(R as record, MyColumn as text) as text => //R = row 1, MyColumn = "Job Name" let Text = Record.Field(R, MyColumn), //Returns R[Job Name] = "Controller" Source = Text.Length(Text), //Returns length("Controller") = 10 NewSource = Number.ToText(Source), //Returns "10" FinalText = Text.Combine({MyColumn, NewSource}, " ") // "Job Name" & " " & "10" in FinalText // "Job Name 10"- Anonymous3 years agoNot applicable
Sorry for the late reply.
In this function, I have two parameters: R & MyColumn. MyColumn works as a drop-down so I can pick a column from the drop-down list, but R is a parameter that I have to hand-write. See below:
- AlexisOlson3 years agoSuper User
Unfortunately, I can't think of any way to make this work using the Invoke Custom Function GUI and zero manual typing but typing fn_Len(_, "Job Name") in the Custom Column GUI isn't that bad (use Query1 instead of fn_Len if that's what your function is named).