powerbi - 使用当前行值对 Power BI 中具有匹配列名的表执行计算?
问题描述
我有两张正在使用的桌子。一个是大约 50 列的大型数据集。第二个表是Table.Schema()
第一个数据集的表。
我正在尝试构建一个类似于Table.Profile()
但具有更多自定义功能的数据质量报告。但是,我什至无法为每个源列重新创建 Table.Profile 的基本元素,例如 Counta 或 Count of null 。
如何使用架构Name
值对架构名称表示的数据源列执行计数计算?请参阅下面的架构表以获取所需的输出,计算数据源中非空值的数量。
注意:由于我希望构建此公式的大量列,因此它是基于名称值的动态,而不是将 50 多个列名称硬编码到公式中
数据源
ID | Status | Created | Modified
1 | Active | 1/1/19 | null
2 | null | 1/5/15 | 1/6/15
3 | Active | null | null
架构
Name | Type | Counta
ID | Number | 3
Status | Text | 2
Created | Date | 2
Modified | Date | 1
解决方案
我将给出计数、非空计数和不同计数的示例,因此您可以看到该模式的几个实例。
我假设您的表数据位于名为Table
. 下面是添加我上面提到的计数的完整高级编辑器视图。
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.Schema
然后Table.Profile
添加额外的分析。
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
引用列与上面的示例相同,但这会让您处于更稳健的状态。
推荐阅读
- reactjs - React npm start 在远程服务器上不起作用。端口问题
- c++ - 使用 opencv 在 GPU 上调整图像大小会产生空输出矩阵
- python - 将 python 脚本的输出读入 C 程序而不创建临时文件以在程序之间传递值
- angular - 角度 - 如何循环倒计时与当前时间
- java - Java 迭代器如何检测集合被修改为抛出 ConcurrentModificationException?
- android - 警报对话框中的可滚动布局,底部有一个按钮(使用约束布局)
- java - 注释内类的 SonarQube 自定义 Java 规则
- firebase - Flutter:Firebase 当前用户抛出错误“方法在 null 上调用”
- c# - Razor 页面 @functions 中的异步
- azure - Azure DevOps 发布管道:从变量组中检索 Key Vault Secret 的版本号