Forum Discussion
Weighted Average on Narrow Table Using DAX Measure
- Anonymous2 years ago
Hi WishAskedSooner ,
First of all, many thanks to lbendlin for your very quick and effective replies.
Based on my testing, please try the following methods:
1.Create the simple table.
2.Create the new measure to calculate sum across all entry id.
Weighted Average = DIVIDE( SUMX( FILTER( 'Fact Table', RELATED('Dim Table'[Category]) = "A" ), 'Fact Table'[Value] * LOOKUPVALUE('Fact Table'[Value], 'Fact Table'[EntryID],'Fact Table'[EntryID], 'Dim Table'[Category], "B") ), CALCULATE(SUM('Fact Table'[Value]), ALL('Dim Table'), 'Dim Table'[Category] = "B") )3.Select the measure and edit the number of shown for the value.
4.Drag the measure into the card visual. The result is shown below.
You can also view the following links to learn about DAX function.
LOOKUPVALUE function (DAX) - DAX | Microsoft Learn
SUMX function (DAX) - DAX | Microsoft Learn
Best Regards,
Wisdom Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi WishAskedSooner ,
First of all, many thanks to lbendlin for your very quick and effective replies.
Based on my testing, please try the following methods:
1.Create the simple table.
2.Create the new measure to calculate sum across all entry id.
Weighted Average =
DIVIDE(
SUMX(
FILTER(
'Fact Table',
RELATED('Dim Table'[Category]) = "A"
),
'Fact Table'[Value] * LOOKUPVALUE('Fact Table'[Value], 'Fact Table'[EntryID],'Fact Table'[EntryID], 'Dim Table'[Category], "B")
),
CALCULATE(SUM('Fact Table'[Value]), ALL('Dim Table'), 'Dim Table'[Category] = "B")
)
3.Select the measure and edit the number of shown for the value.
4.Drag the measure into the card visual. The result is shown below.
You can also view the following links to learn about DAX function.
LOOKUPVALUE function (DAX) - DAX | Microsoft Learn
SUMX function (DAX) - DAX | Microsoft Learn
Best Regards,
Wisdom Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- WishAskedSooner2 years agoContinued Contributor
Anonymous
Simply, simply Brilliant!!!! I was able to implement this into my actual data model which is slightly more complex than the example I provided (a total of three columns that need to be included in the LOOKUP to filter my fact table properly) and it works beautifully! I can't even begin to describe how thankful I am for your help. I have been agonizing over this for days. Thank you!