样本数据:
Lang|Book_Type|Numbers|Weight
--------------------------------
A | B1 | 20 | 5
------------------------
B | B1 | 20 | 4
------------------------
C | B1 | 30 | 3
------------------------
A | B2 | 40 | 5
------------------------
B | B2 | 20 | 4
------------------------
C | B2 | 50 | 10
------------------------
A | B3 | 20 | 2
------------------------
B | B3 | 20 | 5
------------------------
C | B3 | 50 | 10
因此,基本上,这里的问题陈述是我希望另一列/度量的每种书本类型的平均百分比为%,例如:
B1:A:20 /(20 + 20 + 30)= 28.5%B:28.5%C:42.8% B2:A:40 /(40 + 20 + 50)= 36.36%B:18.18%C:45.45% B2:A:20 /(20 + 20 + 50)= 22.22%B:22.22%C:55.56%
A:平均值(28.5%* 5,36.36%* 5,55.56%* 2)或463.92 /(5 + 5 + 2)或38.66
同样,对于B&C。
我尝试使用每个类别的加权平均值,但数字似乎并不十分准确。还有另一种方法吗?
答案 0 :(得分:0)
用作数据集(NewTable):
TAVG =
DATATABLE(
"Lang", STRING,
"Book_Type", STRING,
"value", INTEGER,
"Weight", INTEGER,
{
{"A","B1","20","5" },
{"B","B1","20","4" },
{"C","B1","30","3" },
{"A","B2","40","5" },
{"B","B2","20","4" },
{"C","B2","50","10"},
{"A","B3","20","2" },
{"B","B3","20","5" },
{"C","B3","50","10"}
}
)
简单的AVG:
Average% =
DIVIDE (
SELECTEDVALUE ( TAVG[value] ),
CALCULATE (
SUM ( TAVG[value] ),
FILTER ( ALL ( TAVG ), TAVG[Book_Type] = SELECTEDVALUE ( TAVG[Book_Type] ) )
)
)
然后您可以为以下内容编写另一种度量标准:
W_avg = SUMX(TAVG, TAVG[Weight] * TAVG[Average%])