Power BI - 未找到表的列 'Column1' 错误

Posted

技术标签:

【中文标题】Power BI - 未找到表的列 \'Column1\' 错误【英文标题】:Power BI - The column 'Column1' of the table wasn't found errorPower BI - 未找到表的列 'Column1' 错误 【发布时间】:2021-12-08 07:23:42 【问题描述】:

我在尝试应用代码并加载查询时遇到错误。

The column 'Column1' of the table wasn't found

查询示例代码如下:

    let 
    BaseUrl = "https://jira.tools.com/rest/api/2/search?jql=project in ('ABC') AND issuetype = 'Test Case'",

    JiraIDPerPage = 1000,
 
    GetJson = (Url) =>
        let 
            RawData = Web.Contents(Url),
            Json    = Json.Document(RawData)
        in  Json,
 
    GetJiraIDCount = () =>
        let Url   = BaseUrl & "&maxResults=0",
            Json  = GetJson(Url),
            Count = Json[#"total"]
        in  Count,
 
    GetPage = (Index) =>
        let Skip  = "&startAt=" & Text.From(Index * JiraIDPerPage),
            Top   = "&maxResults=" & Text.From(JiraIDPerPage),
            Url   = BaseUrl & Skip & Top,
            Json  = GetJson(Url),
            Value = Json[#"issues"]
        in  Value,
 
    JiraIDCount = List.Max( JiraIDPerPage, GetJiraIDCount() ),
    PageCount   = Number.RoundUp(JiraIDCount / JiraIDPerPage),
    PageIndices =  0 .. PageCount - 1 ,
    Pages       = List.Transform(PageIndices, each GetPage(_)),
    JiraID    = List.Union(Pages),
    Table       = Table.FromList(JiraID, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    #"Expanded Column1" = Table.ExpandRecordColumn(Table,"Column1", "id", "key", "fields", "Column1.id", "Column1.key", "Column1.fields")
in
    #"Expanded Column1"

我看不到任何异常生成,但是我尝试应用更改,当 Power BI 加载数据时,它给出了上述错误。

【问题讨论】:

您的 #"Expanded Column1" 说要扩展 "Column1",但似乎没有定义任何此类列。 #"Expanded Column1"变量从#"Expanded Column1" = Table.ExpandRecordColumn(Table,"Column1", "id", "key", "fields", "Column1.id", "Column1.key", "Column1.fields")这一行获取数据,有什么遗漏吗? 对。这仅在 Table 已经有一个名为 Column1 的列时才有意义,但我认为这在您获得的 JSON 中不存在。 你说得对,我在 JSON 响应中找不到 Column1。在上面的代码中处理这个问题的最佳方法是什么? 您实际上想扩展什么?我建议使用您实际从 API 获取的对象的名称。 【参考方案1】:

我能够用下面的代码解决上述问题。

    let 
Source = Json.Document(
            Web.Contents(JIRA_URL,
            [
                RelativePath="rest/api/2/search",
                Query=
                [
                  maxResults="100",
                  jql= EPICS_QUERY,
                  startAt="0",
                  apikey="MjY0MzgyODgyNDg4On5RnBcfBqhio"
                ]
            ]
)),

numIssues = Source[total],

startAtList = List.Generate(()=>0, each _ < numIssues, each _ +100),
 
data        = List.Transform(startAtList, each Json.Document(Web.Contents(JIRA_URL,
            [
            RelativePath="rest/api/2/search",
            Query=
                [
                  maxResults="100",
                 jql=EPICS_QUERY,
                 startAt=Text.From(_),
                  apikey="MjY0MzgyODgyNDg4On5RnBcfBqhio"
                ]
            ]))),

 iLL = List.Generate(
     () => [i=-1, iL= ],
     each [i] < List.Count(data),
     each [
         i = [i]+1,
         iL = datai[issues]
     ],
     each [iL]
 ),
 // and finally, collapse that list of lists into just a single list (of issues)
 issues = List.Combine(iLL), 
 #"Converted to Table" = Table.FromList(issues, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
 #"Expanded Column1" = Table.ExpandRecordColumn(#"Converted to Table", "Column1", "key", "fields", "issue", "fields"),
 #"Expanded fields" = Table.ExpandRecordColumn(#"Expanded Column1", "fields", "assignee", "created", "creator", "description", "issuetype", "parent", "priority", "project", "reporter", "resolution", "resolutiondate", "status", "summary", "updated", "assigneeF", "created", "creatorF", "description", "issuetypeF", "parentF", "priorityF", "projectF", "reporterF", "resolutionF", "resolutiondate", "statusF", "summary", "updated"),
 #"Expanded assignee" = Table.ExpandRecordColumn(#"Expanded fields", "assigneeF", "key", "assignee"),
 #"Expanded creator" = Table.ExpandRecordColumn(#"Expanded assignee", "creatorF", "key", "creator"),
 #"Expanded issuetype" = Table.ExpandRecordColumn(#"Expanded creator", "issuetypeF", "name", "issuetype"),
 #"Expanded priority" = Table.ExpandRecordColumn(#"Expanded issuetype", "priorityF", "name", "priority"),
 #"Expanded project" = Table.ExpandRecordColumn(#"Expanded priority", "projectF", "key", "project"),
 #"Expanded reporter" = Table.ExpandRecordColumn(#"Expanded project", "reporterF", "key", "reporter"),
 #"Expanded resolution" = Table.ExpandRecordColumn(#"Expanded reporter", "resolutionF", "name", "resolution"),
 #"Expanded status" = Table.ExpandRecordColumn(#"Expanded resolution", "statusF", "name", "status"),
 #"Changed Type" = Table.TransformColumnTypes(#"Expanded status","created", type datetimezone, "resolutiondate", type datetimezone, "updated", type datetimezone),
 #"Expanded parentF" = Table.ExpandRecordColumn(#"Changed Type", "parentF", "key", "parent")
in
 #"Expanded parentF"

【讨论】:

您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center。

以上是关于Power BI - 未找到表的列 'Column1' 错误的主要内容,如果未能解决你的问题,请参考以下文章

在 Power BI 中拆分自定义字段

在流分析中将时间戳拆分为单独的列,以便在 Power BI 中进行进一步筛选

power bi 中 如何 排序 列?

是否可以通过 Power BI 获取数据透视表的来源?

如何在 Power BI 中合并两个基于非键表的表

Power BI 中的 Power Query 帮助