Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
JJ_NetCo
Frequent Visitor

Weighed calculation from table with DAX

Hi there. I have data like this in my FactTable:

 

WeekTeamTypeScore
32OAA35
32OAB72
32OSA80
32OSB55
33OAA47
33OAB56
33OSA73
33OSB12


I need to group this into week, team, score(no type). But I want to calculate the grouped score, so that Type A=33,33% and B=66,66%

So a weighed result something like in SQL:

SUM(when type='a' then score*0.333

 when type='a' then score*0.666)

But how to formulate this in DAX ? New measure or column?

1 ACCEPTED SOLUTION
jdbuchanan71
Super User
Super User

Hello @JJ_NetCo 

You can do it with DAX like so.

Weighted = 
SUMX(
    'Table','Table'[Score] *
    IF ( 'Table'[Type] = "A",.33,.66)
)

weightedscore.jpg 

View solution in original post

5 REPLIES 5
JJ_NetCo
Frequent Visitor

Both solutions work., thanks.

But I still face an issue. If I put the data in a chart with teams in axis and weighed score in value, it works fine when selecting one week. If I select 2 week(in slicer), it sums the score. If I choose avarage of score as value, then...yes..it's the average of week 32 and 33. I don't need average or score, I need it to recalculate the weighed score for 2 weeks.

I also have another column 'region' in my data where all values are 'O'. So if I put region/team in my axis, I face same problem if I drill up from team-level(O is average of result for OA and OS).  Average (or Sum) instead of recalculating.

Any ideas?

I have my Fact table and Dim connections set up right(one-to-many, ).    

@JJ_NetCo 

How would you calculate the weighted score for 2 weeks?  Lets take OA type A for weeks 32 and 33

Week Team Type Score Weight Score
32 OA A 35 33.33% 11.6655
33 OA A 47 33.33% 15.6651

What would you expect the value for this to be if you select both week 32 and 33?  (35+47) / 2  * 33.33% is the same as AVERAGE (11.6655, 15.6651)

For the the additional column, are you able to share your .pbix file for us to look at?  I'm not really clear on the problem you are seeing without knowing the layout.

Hi again. I found the problem and now it's solved. 

 

The data I provided in the table was a much simplified version of my data. Before persenting the score, there are lots of other calculations, both in Power Bi and sql-server. The problem was that score is a percentage measure(not just SUM), so you cannot just take the average of weeks to get the right period-based result.

Anyway, your suggestions helped me solve the problem.

 

jdbuchanan71
Super User
Super User

Hello @JJ_NetCo 

You can do it with DAX like so.

Weighted = 
SUMX(
    'Table','Table'[Score] *
    IF ( 'Table'[Type] = "A",.33,.66)
)

weightedscore.jpg 

Anonymous
Not applicable

Hey buddy,

 

i think i got a solution.

if helps you, mark me as solution, if not, let me know.

image.pngimage.png

 

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.