Forum Discussion

dd88's avatar
dd88
Post Patron
3 years ago

Power Bi – query or formula to Get Table name

I have 6 tables.

 

In each table, I would like to add a new column.  with a formula to get the current table.Name,  and add the value in the new column.

 

In Power Bi, the table has properties. For example I would have thought the following value could be obtained -

strTableName = Table.Properties.Name

and the value is populated in the new column

 

I have done a search, and  thought this was a simple task/ query.

 

TIA

6 Replies

  • ImkeF's avatar
    ImkeF
    Community Champion

    Hi dd88 
    that's not possible, unfortunately. 
    The only workaround I see is to use the import from folder method for your queries. Then you would be able to use the original file name for it automatically.

      • jbwtp's avatar
        jbwtp
        Memorable Member

        Hi dd88,

        I suspect that you and Imke may have in mind different "tables". Her suggestions (as it appears to me) relates to file names being derived and then assigned as strTableName. Which is, of course, correct, but it looks like what you want/talk about in your question is the actual query name (aka table name), which you assign to the query in PBI. Is this right?

        If yes, I do not think that there is a way to solve it using a function in PBI. Queries are unaware of their own name (or any other query name in the PBI project) in the sense that is supported in the Excel object model, for example. There is a global enumerator for the namespace in PBI - #shared - but there is no way for the query to tell which of the global objects in the enumerator is which.

        However, as the name is "hard-coded" you can just add a column with a fixed value. If you are planning to use the query as a template, you can make the first step a parameter containing the tableName value (this way, you can quickly find/replace it in the code.

         

        Cheers,

        John

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi dd88 ,

     

    When you connected to an excel file successfully, you can select a table and click on the source step, which will have the Sheet's name column. 

     

    Best Regards,

    Stephen Tao

     

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.