Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
Good morning,
I have the following simplified universe:
The OPINION table stores the opinion (from 1 to 10) of certain users for different questions (each user can answer just once):
The Countries table stores the countries in which each user is relevant:
I want a measure that calculates the average opinion of each user * count of the user in the table countries:
For example, if I had a table by question, the result shoud be calculated like this:
P1: User A (3 * 1) + User B (7 * 2) + User C (5 * 3) + User D (2 * 0) / (1+2+3+0) = 5,33
P2: User A(9 * 1) + User B (5 * 2) / (1+2) = 6,33
Any suggestion?
Thank you so much!
Solved! Go to Solution.
Your model is worse than you might think. You have to change it.
<-- This is what should be visible in the Fields pane
And measures:
# User Countries =
CALCULATE(
DISTINCTCOUNT( UserCountryBridge[CountryID] ),
REMOVEFILTERS( Countries )
)
Opinion Value =
var UserAvgValueWithCountryCounts =
ADDCOLUMNS(
DISTINCT( Users[UserID] ),
"@AverageValue",
CALCULATE(
AVERAGE( Opinions[Value] )
),
"@CountryCount",
CALCULATE(
DISTINCTCOUNT( UserCountryBridge[CountryID] ),
REMOVEFILTERS( Countries )
)
)
var Result =
DIVIDE(
SUMX(
UserAvgValueWithCountryCounts,
[@AverageValue] * [@CountryCount]
),
SUMX(
UserAvgValueWithCountryCounts,
[@CountryCount] * (1 - ISBLANK( [@AverageValue] ) )
)
)
return
Result
Please do understand the logic of the measure in all the situations you'll be using it in. If in some of them you don't get what you need, then modify the measure to your heart's content.
User | Count |
---|---|
22 | |
11 | |
8 | |
6 | |
6 |
User | Count |
---|---|
25 | |
13 | |
11 | |
9 | |
6 |