Forum Discussion
calculate dynamic average measure
I have this data
| category | country | metric |
| A | US | 20 |
| A | Canada | 10 |
| A | Both | 30 |
- Anonymous2 years ago
Hi kulpowerbi ,
According to your description, here are my steps you can follow as a solution.
(1) My test data is the same as yours.
(2) We can create a slicer table.
Table 2 = EXCEPT(VALUES('Table'[country]),{"Both"})(3) We can create a measure.
average = var _a=CALCULATE(SUM('Table'[metric]),'Table'[country]= "Both" ) var _b=COUNTROWS(ALLSELECTED('Table 2')) var _c=IF(ISFILTERED('Table 2'[country]),1,0) var _d=CALCULATE(SUM('Table'[metric]),FILTER(ALL('Table'),'Table'[country] in VALUES('Table 2'[country]))) RETURN DIVIDE(_d+_a,_b+_c)(4) Then the result is as follows.
Best Regards,
Neeko Tang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
2 Replies
- Daniel29195Community Champion
hello
try this code :
measure =var c = calculate(max(table_name[metric]) , country = Both )
var t = if( isfiltered( table_country[country_column]) , 1 , 0 )
var res =
( sum(metric) + c ) / countrows(table_name) + t
return res
let me know if it works for you .
If my response has successfully addressed your issue kindly consider marking it as the accepted solution! This will help others find it quickly. Dont forget to hit that thumbs up button 🫡👍
- AnonymousNot applicable
Hi kulpowerbi ,
According to your description, here are my steps you can follow as a solution.
(1) My test data is the same as yours.
(2) We can create a slicer table.
Table 2 = EXCEPT(VALUES('Table'[country]),{"Both"})(3) We can create a measure.
average = var _a=CALCULATE(SUM('Table'[metric]),'Table'[country]= "Both" ) var _b=COUNTROWS(ALLSELECTED('Table 2')) var _c=IF(ISFILTERED('Table 2'[country]),1,0) var _d=CALCULATE(SUM('Table'[metric]),FILTER(ALL('Table'),'Table'[country] in VALUES('Table 2'[country]))) RETURN DIVIDE(_d+_a,_b+_c)(4) Then the result is as follows.
Best Regards,
Neeko Tang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.