特定产品的销售额总和高于总销售额的 2% 的产品计数 - Power BI - DAX Measure
Count of products where sum of sales for particular product is higher than 2% of total sales - Power BI - DAX Measure
我有销售额的事实表
我想创建一个度量值来计算特定产品的销售额总和高于总销售额的 2% 的产品数量。
例如:
1. 'ProductKey' 310的销售总额为5000。
2. 'ProductKey'346 的销售总额为 2000。
3.总销售额的2%为3000。
产品 310 将包括在计数中,产品 346 将不包括在计数中。
我将如何写这样的措施?
我试过创建这样的东西:
Big Sales =
var SalesTotal = CALCULATE(SUM(fact_InternetSales[SalesAmount]))
var twoperceSalesAmount =
CALCULATE (SUM(fact_InternetSales[SalesAmount]), ALL( fact_InternetSales )) * 0.02
return
CALCULATE (COUNT(fact_InternetSales[ProductKey]),
FILTER (fact_InternetSales, SalesTotal - twoperceSalesAmount > 0))
谢谢
亲切的问候,
罗伯特
你快到了。
伪算法是:
1.计算阈值
2. 只考虑销售额超过阈值的产品
3.统计产品数量
Big Sales:=
var _threshold = CALCULATE(SUM(fact_InternetSales[SalesAmount]),ALL(fact_InternetSales))*0.02
var _productlist =
FILTER(ADDCOLUMNS(
SUMMARIZE(
fact_InternetSales,
fact_InternetSales[ProductKey),
"productsales",CALCULATE(SUM(fact_InternetSales[SalesAmount]))),
[productsales]>_threshold)
RETURN
Countrows(_productlist)
如果网速很慢可以优化一下
使用 SUMX 的解决方案也有效:
Big Sales SUMX =
SUMX(VALUES(fact_InternetSales[ProductKey]),
IF(CALCULATE(SUM(fact_InternetSales[SalesAmount]))>
CALCULATE(SUM(fact_InternetSales[SalesAmount]),ALL(fact_InternetSales))*0.02,1))
我有销售额的事实表
我想创建一个度量值来计算特定产品的销售额总和高于总销售额的 2% 的产品数量。 例如: 1. 'ProductKey' 310的销售总额为5000。 2. 'ProductKey'346 的销售总额为 2000。 3.总销售额的2%为3000。 产品 310 将包括在计数中,产品 346 将不包括在计数中。 我将如何写这样的措施? 我试过创建这样的东西:
Big Sales =
var SalesTotal = CALCULATE(SUM(fact_InternetSales[SalesAmount]))
var twoperceSalesAmount =
CALCULATE (SUM(fact_InternetSales[SalesAmount]), ALL( fact_InternetSales )) * 0.02
return
CALCULATE (COUNT(fact_InternetSales[ProductKey]),
FILTER (fact_InternetSales, SalesTotal - twoperceSalesAmount > 0))
谢谢
亲切的问候, 罗伯特
你快到了。
伪算法是:
1.计算阈值
2. 只考虑销售额超过阈值的产品
3.统计产品数量
Big Sales:=
var _threshold = CALCULATE(SUM(fact_InternetSales[SalesAmount]),ALL(fact_InternetSales))*0.02
var _productlist =
FILTER(ADDCOLUMNS(
SUMMARIZE(
fact_InternetSales,
fact_InternetSales[ProductKey),
"productsales",CALCULATE(SUM(fact_InternetSales[SalesAmount]))),
[productsales]>_threshold)
RETURN
Countrows(_productlist)
如果网速很慢可以优化一下
使用 SUMX 的解决方案也有效:
Big Sales SUMX =
SUMX(VALUES(fact_InternetSales[ProductKey]),
IF(CALCULATE(SUM(fact_InternetSales[SalesAmount]))>
CALCULATE(SUM(fact_InternetSales[SalesAmount]),ALL(fact_InternetSales))*0.02,1))