admin管理员组文章数量:1356241
I have 2 columns in a table UPS as follows
Location 1st Service Age 2nd Service Age
town1 3 0
town2 5 2
town3 6 0
town4 0 0
town5 2 1
How can I calculate (measure) the average age of both columns, ignoring 0's and slicer. For the above the answer should be 19/6 = 3.17, if all zeros, give 0.00
Thank you in advance
I have 2 columns in a table UPS as follows
Location 1st Service Age 2nd Service Age
town1 3 0
town2 5 2
town3 6 0
town4 0 0
town5 2 1
How can I calculate (measure) the average age of both columns, ignoring 0's and slicer. For the above the answer should be 19/6 = 3.17, if all zeros, give 0.00
Thank you in advance
Share Improve this question edited Mar 29 at 16:27 DarkBee 15.5k8 gold badges72 silver badges117 bronze badges asked Mar 29 at 16:07 cghantacghanta 373 bronze badges 2 |1 Answer
Reset to default 1There's quite a few ways to do this, but here's probably the easiest to follow. You'll need three calculations against your table. These could all be conducted in one measure or broken out individually, as shown below:
Total_Sum
Total_Sum = SUM('UPS'[1st Service Age]) + SUM('UPS'[2nd Service Age])
Non_Zero_Count
Non_Zero_Count =
SUMX(
'UPS',
IF('UPS'[1st Service Age] = 0, 0, 1) + IF('UPS'[2nd Service Age] =0, 0, 1)
)
AVG_AGE
AVG_AGE = if([Non_Zero_Count]=0,0,
DIVIDE([Total_Sum], [Non_Zero_Count]))
or combined to single measure
singleCalc =
VAR Total_Sum = SUM('UPS'[1st Service Age]) + SUM('UPS'[2nd Service Age])
VAR Non_Zero_Count =
SUMX(
'UPS',
IF('UPS'[1st Service Age] = 0, 0, 1) + IF('UPS'[2nd Service Age] =0, 0, 1)
)
RETURN
if(Non_Zero_Count=0,0,Total_Sum/Non_Zero_Count)
本文标签: powerbiCalculate average of 2 columns ignoring zerosStack Overflow
版权声明:本文标题:powerbi - Calculate average of 2 columns ignoring zeros - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744012893a2575891.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
19/6
. I see the10
integers sum to19
which no doubt is the numerator coming from from2
columns and5
rows, but I don't see the route to a divisor of6
. – pgSystemTester Commented Mar 29 at 16:26