首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用当前行值在Power中使用匹配的列名对表执行计算?

使用当前行值在Power中使用匹配的列名对表执行计算?
EN

Stack Overflow用户
提问于 2019-08-23 17:18:23
回答 1查看 1.2K关注 0票数 0

我有两张桌子在工作。一个是一个大的数据集,大约有50列。第二个表是第一个数据集的Table.Schema()

我正在尝试构建一个类似于Table.Profile()的数据质量报告,但需要更多的定制。但是,我甚至无法为每个源列重新创建Table.Profile的基本元素,如Counta或null计数。

如何使用架构Name值对架构名称表示的数据源列执行计数计算?有关所需输出,请参见下面的架构表,计算数据源中非空白值的数量。

注意:由于有大量的列,我希望构建这个公式,因此它是基于名称值的动态的,而不是将50+列名硬编码成公式。

数据源

代码语言:javascript
复制
ID | Status | Created | Modified
1  | Active | 1/1/19  | null
2  | null   | 1/5/15  | 1/6/15
3  | Active | null    | null

模式

代码语言:javascript
复制
Name     | Type   | Counta 
ID       | Number | 3
Status   | Text   | 2
Created  | Date   | 2
Modified | Date   | 1
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-08-23 18:54:18

我将给出使用count、非空计数和不同计数的示例,这样您就可以看到模式的几个实例。

我假设您的表数据位于一个名为Table的表中。下面是用于添加上述计数的完整高级编辑器视图。

代码语言:javascript
复制
let
     srcTable = Table // This is an arg to all steps below, so useful to have here
    ,schema = Table.Schema(srcTable) // you've used this
    ,count =
        Table.AddColumn( // self-descriptive
             schema      // the source table to add this new column to
            ,"Count"     // the name of the new column we are adding
            // below is a function to evaluate per row in the source table
            // The way to reference a table column by name is
            // Table.Column(table, "column"). That returns a list.
            ,each List.Count(Table.Column(srcTable, _[Name])))
    ,nonNullCount =
        Table.AddColumn(
             count
             ,"Non-null count"
             ,each List.NonNullCount(Table.Column(srcTable, _[Name])))
    ,distinctCount =
        Table.AddColumn(
             nonNullCount
             ,"Distinct Count"
             ,each List.Count(List.Distinct(Table.Column(srcTable, _[Name]))))
in
    distinctCount

实际上,我不会尝试重新实现Table.Profile。我将加入Table.SchemaTable.Profile的结果,然后添加额外的分析。

代码语言:javascript
复制
let
     srcTable = Opportunity // This is an arg to all steps below, so useful to have here
    ,schema = Table.Schema(srcTable) // you've used this
    ,profile = Table.Profile(srcTable)
    ,schemaAndProfile =
        Table.NestedJoin(
             schema
            ,"Name"
            ,profile
            ,"Column"
            ,"profile"
        )
    ,expandProfile =
        Table.ExpandTableColumn(
             schemaAndProfile
            ,"profile"
            ,{"Min", "Max", "Average", "StandardDeviation", "Count", "NullCount", "DistinctCount"}
            ,{"profile.Min", "profile.Max", "profile.Average", "profile.StandardDeviation", "profile.Count", "profile.NullCount", "profile.DistinctCount"})
in
    expandProfile

引用列与上面的示例相同,但这将在更健壮的状态下启动。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57630613

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档