cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
DaleHohm
Advocate II
Advocate II

How to retrieve "correct" column names from SharePoint lists

When you load data from a SharePoint list, the columns are named using an "Internal" name rather than the "Display" name that exposed when interacting with SharePoint. 

 

Is there a PowerQuery recipe that can be used to retrieve the display names and overwrite the internal names while importing into Power BI?

 

For example, when I retrieve a list from SharePoint, the names of the columns often do not match the column names displayed in SharePoint.  For example:

 

"Primary Geography Country" is brought in as "Primary Geography Co"

"Launch: Overall Readiness" is brought in as "Launch: Overall_x002"

"Complete" gets brought is as "AllDone" (because I had originally called the column AllDone and then changed it)

"Introduction" gets brought in as "Title" (because I changed Title to Introduction)

 

I am hopeful that the display names are actually in the data, so I'm looking for a recipe to drill into the nested lists and records in what is returned for the list to get the display names.  My hope is that these are stored consistently in the data structures, regardless of the type of data each column holds.

 

Dale

 

p.s. This is a repost of a question in a thread that took a wrong turn: https://community.powerbi.com/t5/Desktop/SharePoint-Lists-how-to-get-Display-names/m-p/483977#M22534...

1 ACCEPTED SOLUTION

I've now encapsulated this into a function.  See the comments for usage example:

 

fnRealSpColumnNames

(sharePointSite, listName)=>
let
    // After connecting to a SharePoint list, pass in the SharePoint site name and list name to this function inside a Table.RenameColumns call.
    // The function returns the InternalName and DisplayName of each of the list column names.
    // For example:
    //  = Table.RenameColumns(#"previous step name", fnRealSpColumnNames("https://xxx.sharepoint.com/teams/yoursite/", "Your ListName"), MissingField.Ignore)
    Source = OData.Feed(sharePointSite & "/_api/web/lists/GetByTitle('" & listName & "')/Fields?$select=Title,InternalName", null, [Implementation="2.0"]),
    recs = Table.ToRecords(Source),
    lsts = List.Transform(recs, each Record.ToList(_))
in
    lsts

 

View solution in original post

16 REPLIES 16
v-chuncz-msft
Community Support
Community Support

@DaleHohm 

 

SharePooint API provides only internal columns names and we use this names in queries.

If a user create a column with exact name and later decide to change it - we could not be able to display the new name. SharePoint API will still return the original name.

Here could be a workaround: create a new column with desired name, copy data to it and remove the old column.

Community Support Team _ Sam Zha
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
abdul_Kochi
Advocate I
Advocate I

I am experiencing the same issue, please do the following steps.

 

Edit Query-->Source

Change ApiVersion = 14

= SharePoint.Tables("your sharepoint site address", [ApiVersion = 14])

 

To get the correct column name of sharepoint listTo get the correct column name of sharepoint list

Thanks abdul_Kochi for this easy solution. 😊👍

Anonymous
Not applicable

@abdul_Kochi spot on thanks!

Anonymous
Not applicable

For those that are interested, I use this tool extensively. It shows the InternalName and Title fields side-by-side, along with TypeAsString. It's invaluable to me in using Power BI and SharePoint O365 lists. I simply copy the Title field from the tool and paste it into Power BI that used the InternalName for the column name. It also is a big help in assigning the correct data type to the column, since the default in Power BI is 'Any' for SP data.

If only Power BI would utilize the InternalName behind the scenes to keep columns straight, but use the Title field as the actual column name displayed. The tool makes it easy, but it's still laborious to copy and paste for every column. And while I'm wishing, it be nice to auto-map the data types as well.

DaleHohm
Advocate II
Advocate II

OK, I found the column display name information... it is in ContentType, Fields, Title (really?  obviously the last place I looked).

 

Power Query and Power BI should make it easy to surface these names!

 

let
    //SPListURL is the URL of sharepoint site
    Source = SharePoint.Tables(SPListURL, [ApiVersion = 15]),
    //ListTitle is the name of Sharepoint list
    SPList = Source{[Title=ListTitle]}[Items],
    #"Removed Other Columns" = Table.SelectColumns(SPList,{"ContentType"}),
    ContentType = #"Removed Other Columns"{0}[ContentType],
    Fields = ContentType[Fields],
    #"Removed Other Columns1" = Table.SelectColumns(Fields,{"InternalName", "Title"})
in
    #"Removed Other Columns1"

Using an OData query, I've found a another way of getting the display name (aka Title) and the InternalName of list columns.  This works even with Survey lists (my previous solution did not).

 

Create an OData query of the form:

https://xxxx.sharepoint.com/your-site/_api/web/lists/GetByTitle('your-list')/Fields?$select=Title,InternalName

 

use $select=* to see all of the metadata available.

 

Dale

I there,  could you please provide more detail on how to do this?

 

Thanks

@Hayleysea I'll presume you have already brought in your SharePoint List into Power Query.

 

Create a new query called RealNames using the OData connector and the Odata query as I defined before. This will bring you a table with columns InternalName and Title (aka RealName).  Transform this into a list or records, then the records into lists.  The items in this final list become the name-value pairs for your rename operation.

 

let
Source = OData.Feed("your-tenant/yoursite/_api/web/lists/GetByTitle('yourlist')/Fields?$select=Title,InternalName", null, [Implementation="2.0"]),
recs = Table.ToRecords(Source),
lsts = List.Transform(recs, each Record.ToList(_))
in
lsts

 

Then back in your query where you brought in the SharePoint list, append this line:

 

= Table.RenameColumns(#"your previous step name", RealNames, MissingField.Ignore)

 

This will replace the names of any column whose internal name matches and ignore the others.

 

Dale

I've now encapsulated this into a function.  See the comments for usage example:

 

fnRealSpColumnNames

(sharePointSite, listName)=>
let
    // After connecting to a SharePoint list, pass in the SharePoint site name and list name to this function inside a Table.RenameColumns call.
    // The function returns the InternalName and DisplayName of each of the list column names.
    // For example:
    //  = Table.RenameColumns(#"previous step name", fnRealSpColumnNames("https://xxx.sharepoint.com/teams/yoursite/", "Your ListName"), MissingField.Ignore)
    Source = OData.Feed(sharePointSite & "/_api/web/lists/GetByTitle('" & listName & "')/Fields?$select=Title,InternalName", null, [Implementation="2.0"]),
    recs = Table.ToRecords(Source),
    lsts = List.Transform(recs, each Record.ToList(_))
in
    lsts

 

View solution in original post

@DaleHohm  I've been struggling with this for a while and your solution looks like a good one. Would it be possible for you to break down the steps required to apply this solution for someone who has very little experience with creating functions? 

 

Many thanks in advance if you can!

Hello,

 

It is possbile to explain how to execute this function?


Thanks and br, 

v-jiascu-msft
Microsoft
Microsoft

Hi Dale,

 

I have reported this issue to the Product Team. I will update here later.

 

Best Regards,

Dale

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

Hi Dale,

 

The report ID is CRI 79818387.

 

Best Regards,

Dale

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

Thanks very much Dale!

 

Is there a way for me to watch this CRI or get feedback if/when it is updated?

 

Dale

Hi Dale,

 

I will update the latest information here.

 

Best Regards,

Dale

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

Helpful resources

Announcements
User Groups Public Preview

Join us for our User Group Public Preview!

Power BI User Groups are coming! Make sure you’re among the first to know when user groups go live for public preview.

March Update

Check it Out!

Click here to read more about the March 2021 Updates!

secondImage

The largest Power BI virtual conference

100+ sessions, 100+ speakers, Product managers, MVPs, and experts. All about Power BI. Attend online or watch the recordings.