Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
ValeriaBreve
Post Patron
Post Patron

Use a formula for a column name

Hello,

I am trying to use a formula to call a column name to avoid tedious and long code rewriting (many years to compile....).

In particular, I am reading the Year from the column name: 

YearOfRef = Text.Range(Table.ColumnNames(#"Promoted Headers"){48},4,4)

 

Now, I have a column that says "Jan 2016 Volume" as an example.

I can refer to it as "Jan " & YearOfRef & " Volume"

 

But when it comes to other parts of my code, I have an expression like this:

....

each List.Sum([("Jan 2016 Volume")])

....

 

So in square brackets. How do I insert my YearOfRef there? I cannot seem to find a way.

Thanks!

Kind regards

Valeria

 

1 ACCEPTED SOLUTION

@ValeriaBreve You can use this - 

 

GroupedRows = 
    Table.Group ( 
        #"Changed Type", 
        {"Product"}, 
        {
            {
                "Amount", 
                (Rows)=> // All Rows & Columns visible for the current Product
                List.Sum (  
                    Table.Column ( 
                        Rows, 
                        "Jan" & Number.ToText ( Year ) & "Volume"  
                    )  
                )
            } 
        }
    )

 

View solution in original post

6 REPLIES 6
ValeriaBreve
Post Patron
Post Patron

@AntrikshSharma Hello, sure! It is used in

 

#"Grouped Rows" = Table.Group(#"Changed Type", {"Product"}, {{"Amount", each List.Sum([Jan 2016 Volume])}})

 

So if I replace the [Jan 2016 Volume] with Table.Column( Table, "Jan 2016 Volume" ) I get the summed volume for the whole column, regardeless of the grouping...

 

 

 

@ValeriaBreve You can use this - 

 

GroupedRows = 
    Table.Group ( 
        #"Changed Type", 
        {"Product"}, 
        {
            {
                "Amount", 
                (Rows)=> // All Rows & Columns visible for the current Product
                List.Sum (  
                    Table.Column ( 
                        Rows, 
                        "Jan" & Number.ToText ( Year ) & "Volume"  
                    )  
                )
            } 
        }
    )

 

It works very well! Thank you so much 🙂

AntrikshSharma
Super User
Super User

You can use Table.Column ( Table, "Jan 2016 Volume" ) it will return a List and then you can pair it with List.Sum

Hello thanks, maybe I did not understand the solution, my whole point is to avoid any hard coded reference to the year, being able to call the column with the help of YearOfRef... otherwise the query will fail for 2017, 2018,... and I have MANY column per year. Thanks!

You can replace the 2016 in the code I provided with a refrence to whatever is there in your data, from this point onward I need raw data and final result, it is hard to deduce from text chats what you want.

Helpful resources

Announcements
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors