[英]Calculate Average Number of Days Between Multiple Dates with dax in power bi
[英]How to calculate the average of multiple categories in Power-BI DAX?
我有一個包含以下列的表格:
行業表
Industry_ID Score
1 2
1 3
2 2
2 4
3 0
4 2
我需要計算每個行業的平均值,然后計算這些平均值的平均值。
喜歡分數的平均值
1=(2+3)/2 =>2.5
2=(2+4)/2 =>3
3=0/1 => 0
4=2/1 => 2
然后是這些平均值的平均值,即 (2.5+3+0+2)/4 => 1.85
這些表是直接查詢的,所以請考慮一下。 任何幫助表示贊賞。 謝謝
以下是實現這一目標的兩種方法:
只需在 RETURN 部分中的個人和總體平均變量之間切換,還將此代碼CALCULATE ( COUNTROWS ( Industry ) )
存儲在單獨的度量中,以便它可以在各個地方重復使用而不會使代碼冗長
Industry Average =
VAR AllIndustryAverages =
AVERAGEX (
ALL ( Industry[IndustryID] ),
DIVIDE ( [Total Score], CALCULATE ( COUNTROWS ( Industry ) ) )
)
VAR IndividualAverages =
AVERAGEX (
VALUES ( Industry[IndustryID] ),
DIVIDE ( [Total Score], CALCULATE ( COUNTROWS ( Industry ) ) )
)
RETURN
IndividualAverages
Industry Average 2 =
VAR VisibleIndustries =
VALUES ( Industry[IndustryID] )
VAR AllIndustryAverages =
ADDCOLUMNS (
ALL ( Industry[IndustryID] ),
"Average",
VAR CurrentIndustryTotalScore = [Total Score]
VAR IndustryCount =
CALCULATE ( COUNTROWS ( Industry ) )
RETURN
DIVIDE ( CurrentIndustryTotalScore, IndustryCount )
)
VAR IndividualAverages =
AVERAGEX (
FILTER ( AllIndustryAverages, Industry[IndustryID] IN VisibleIndustries ),
[Average]
)
VAR OverallAverage =
AVERAGEX ( AllIndustryAverages, [Average] )
RETURN
IndividualAverages
要創建不同值的平均值,請創建一個計算列,如下所示:
Average = var no_ID = 'Table'[Industry_ID] Return AVERAGEX( FILTER(ALL('Table'), 'Table'[Industry_ID] = no_ID), 'Table'[Score] )
這將為您提供一個具有不同Industry_ID
平均值的列。
要創建平均值的平均值,請創建如下度量:
Measure = AVERAGEX(SUMMARIZE('Table', 'Table'[Industry_ID], 'Table'[Average]), 'Table'[Average])
最終輸出-
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.