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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
rjrn
Frequent Visitor

Error when SharePoint list is empty

I am pulling data from a SharePoint list (on premisse SharePoint), but when the list has no lines, I get an error "The column 'ID' of the table wasn't found".

 

let
    Source = SharePoint.Tables("https://SharePoint/List/", [ApiVersion = 15]),
    #"22acf0c7-df1f-4e36-b373-97f0aba7dd61" = Source{[Id="22acf0c7-df1f-4e36-b373-97f0aba7dd61"]}[Items],
    #"Renamed Columns" = Table.RenameColumns(#"22acf0c7-df1f-4e36-b373-97f0aba7dd61",{{"ID", "ID.1"}}),
    #"Expanded FieldValuesAsText" = Table.ExpandRecordColumn(#"Renamed Columns", "FieldValuesAsText", {"AssignedTo"}, {"FieldValuesAsText.AssignedTo"}),
    #"Removed Other Columns" = Table.SelectColumns(#"Expanded FieldValuesAsText",{"Id", "Title", "Modified", "Created", "Status", "Comment", "Priority", "StartDate", "DueDate", "PercentComplete", "FieldValuesAsText.AssignedTo"}),
    #"Added Custom" = Table.AddColumn(#"Removed Other Columns", "Region", each "MCLA"),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "AI", each "MCLA3 - Top Deals sniper mode")
in
    #"Added Custom1"

The error is raised on the line #"Renamed Colums", since the Source on the line above returns no records.

 

Please help.

Regards, RN

1 ACCEPTED SOLUTION
rjrn
Frequent Visitor

After a lot of digging and testing, I found a solution to my issue. Sharing here for everybody else.

 

let
    Source = SharePoint.Tables("https://SharePoint/List/", [ApiVersion = 15]),

    //Define the list ID
    #"SPSource" = Source{[Id="22acf0c7-df1f-4e36-b373-97f0aba7dd61"]}[Items],

    //Check if Source is an empty table
//If yes, returns a table with a single row/column "Id=null"
//If not, does the rest of the code CheckEmpty = if Table.IsEmpty(#"SPSource") then #table( type table [Id = number], {{null}} ) else ( let #"Renamed Columns" = Table.RenameColumns(#"SPSource",{{"ID", "ID.1"}}), #"Expanded FieldValuesAsText" = Table.ExpandRecordColumn(#"Renamed Columns", "FieldValuesAsText", {"AssignedTo"}, {"FieldValuesAsText.AssignedTo"}), #"Removed Other Columns" = Table.SelectColumns(#"Expanded FieldValuesAsText",{"Id", "Title", "Modified", "Created", "Status", "Comment", "Priority", "StartDate", "DueDate", "PercentComplete", "FieldValuesAsText.AssignedTo"}), #"Added Custom" = Table.AddColumn(#"Removed Other Columns", "Region", each "XXXX"), #"Added Custom1" = Table.AddColumn(#"Added Custom", "AI", each "XXXXAINAME") in #"Added Custom1" ) in CheckEmpty

View solution in original post

3 REPLIES 3
rjrn
Frequent Visitor

After a lot of digging and testing, I found a solution to my issue. Sharing here for everybody else.

 

let
    Source = SharePoint.Tables("https://SharePoint/List/", [ApiVersion = 15]),

    //Define the list ID
    #"SPSource" = Source{[Id="22acf0c7-df1f-4e36-b373-97f0aba7dd61"]}[Items],

    //Check if Source is an empty table
//If yes, returns a table with a single row/column "Id=null"
//If not, does the rest of the code CheckEmpty = if Table.IsEmpty(#"SPSource") then #table( type table [Id = number], {{null}} ) else ( let #"Renamed Columns" = Table.RenameColumns(#"SPSource",{{"ID", "ID.1"}}), #"Expanded FieldValuesAsText" = Table.ExpandRecordColumn(#"Renamed Columns", "FieldValuesAsText", {"AssignedTo"}, {"FieldValuesAsText.AssignedTo"}), #"Removed Other Columns" = Table.SelectColumns(#"Expanded FieldValuesAsText",{"Id", "Title", "Modified", "Created", "Status", "Comment", "Priority", "StartDate", "DueDate", "PercentComplete", "FieldValuesAsText.AssignedTo"}), #"Added Custom" = Table.AddColumn(#"Removed Other Columns", "Region", each "XXXX"), #"Added Custom1" = Table.AddColumn(#"Added Custom", "AI", each "XXXXAINAME") in #"Added Custom1" ) in CheckEmpty

@rjrn I am new to PBI.  I am having the same issue, but looking at your text above, I am unsure how to edit my query.  Where do you get the APIVersion for the list as well as the list ID and the ID field number?

@rjrn actually I figured it out after I did some clean up on my table.

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

Check out the November 2024 Power BI update to learn about new features.