web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Convert text string to...
Power Apps
Answered

Convert text string to column name

(2) ShareShare
ReportReport
Posted on by 35

Hello,

 

I have written a code were I want to sum column values for filtered data set based on user input. The idea is that app user is free to define column name. I am struggling to convert text string into something that is recognizable as a column name (from "W28" to 'W28'). I have tried to replace double quotes with single quotes, but it doesn't seem to be right approach (Substitute("W28", Char(34),Char(39))). I think format change needs to be applied to the text input, but I haven't managed to figure it out.

 

Can someone help to make attached code easier and more readable by avoiding "if" statement?

Categories:
I have the same question (0)
  • Verified answer
    Adrian_Celis Profile Picture
    1,652 Moderator on at

    Hi @SAZ 

    Unfortunately you can't make the column name dynamic in the Sum function (but anyone is welcome to prove me wrong). That is why sometimes it's better to structure your list vertically like in the picture:

    Adrian_Celis_0-1657815720288.png

    If you have this structure, then you can simply say something like:

     

    With({_project_SAZ:Filter('Planned working hours v2', Name = "Some Name", Category="Project", WColumn = TextInput1.Text)},Sum(_project_SAZ,Value))

     

    But your existing code will work anyway.

  • SAZ Profile Picture
    35 on at

    Thank you Adrian for your input!

    If no-one challenges your answer, I will stay with may current solution. 

  • WarrenBelz Profile Picture
    153,117 Most Valuable Professional on at

    @SAZ ,

    I can confirm @Adrian_Celis 's response - you cannot create column names in a data source dynamically.

  • SAZ Profile Picture
    35 on at

    Thank you WarrenBelz!

  • Nuchem Profile Picture
    128 on at

    "Unfortunately you can't make the column name dynamic in the Sum function"

    You cannot make stringified column names dynamic (i.e. from "" to '') full stop. Which sucks really 🙄

  • elnachota Profile Picture
    6 on at

    Hello, hope that you solved this but in case you couldnt know that this can be solved with the function Expression.Evaluate.

    In my example case (see picture) I had a table which for every line it had a different table embedded in column [Custom], and what I needed to do is to filter that embedded table leaving out any row with null value in the column whose name is given in column [Columna]. 

    That means that the problem is the same as yours, I needed to take a string from column [Columna] and convert it in a column identifier.

    I could solve it with this piece of code:

     

     

     

    = Table.AddColumn(
     #"Added Custom", 
     "Table_filtered", 
     each 
     let
     tabla_de_la_linea = [Custom], 
     columna_para_filtrar = [Columna]
     in
     Expression.Evaluate(
     "Table.SelectRows(tabla_a_evaluar,each " & columna_para_filtrar & " <> null)", 
     [
     Table.SelectRows = Table.SelectRows, 
     tabla_a_evaluar = tabla_de_la_linea, 
     columna_para_filtrar = columna_para_filtrar
     ]
     )
     )

     

     

     

    Hope it helps
  • WarrenBelz Profile Picture
    153,117 Most Valuable Professional on at

    @elnachota ,

    I think you have the wrong forum here - that certainly is not PowerFX code . . .

  • elnachota Profile Picture
    6 on at

    Oh right, I read it quickly and though it was M haha my bad

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 765 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 343 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 272

Last 30 days Overall leaderboard