以下是我所面临的一个现实世界问题的简化示例:假设我有一个带有测量计数的销售事实表,其维度为供应商,客户和零件。我想获取零件的销售总和的最小值,最大值和平均值,但受相关客户和供应商的组合的限制。
这是Sales表和预期结果的示例
<form method="POST" action="{{ url_for('scan.add_experiment_and_scans') }}" enctype="multipart/form-data">
<div class="form-group">
{{experiment_and_scan_form.date.label}}
{{experiment_and_scan_form.date(placeholder="Date of session", class_="form-control")}}
</div>
<div class="form-group">
{{experiment_and_scan_form.scanner.label}}
{{experiment_and_scan_form.scanner(placeholder="Scanner", class_="form-control")}}
</div>
<div class="form-group">
{{experiment_and_scan_form.field_strength.label}}
{{experiment_and_scan_form.field_strength(placeholder="Field Strength", class_="form-control")}}
</div>
{{ experiment_and_scan_form.csrf_token }}
{{ experiment_and_scan_form.hidden_tag() }}
{{ experiment_and_scan_form.scan_file(multiple="multiple") }}
{{ experiment_and_scan_form.submit }}
</form>
因此,我想以某种方式创建的度量必须从VendorKey,CustomerKey和PartKey分组的数据中获取结果(尽管PartKey将在Filter Context中),但是我不知道如何指定这种类型的度量。分组。
答案 0 :(得分:1)
此处的关键是创建一个摘要表,在该表中删除过滤器上下文,然后使用该表进行最小/最大/平均。下方的Summary
表重新创建了您显示的数据表,但两行2,a,Y
已聚合。
AvgSum =
VAR Summary =
SUMMARIZE (
ALL(Table1),
Table1[PartKey],
Table1[VendorKey],
Table1[CustomerKey],
"Cnt", SUM ( Table1[Count] )
)
RETURN
AVERAGEX (
FILTER (
Summary,
Table1[PartKey] = MAX ( Table1[PartKey] )
),
[Cnt]
)
请注意,如果您将上面的AVERAGEX
换成MINX
或MAXX
,则会得到指定的最小和最大