Forum Discussion
DAX calculation for weighted average
- 4 years ago
Hi,
Please check the below picture and the attached pbix file whether it suits your requirement.
Only Bond weight avg: = DIVIDE ( SUMX ( FILTER ( Data, NOT ( Data[Category] IN { "String", "Stock" } ) ), Data[Balance] * Data[Rate] ), SUMX ( FILTER ( Data, NOT ( Data[Category] IN { "String", "Stock" } ) ), Data[Balance] ) )
Hi,
Please check the below picture and the attached pbix file whether it suits your requirement.
Only Bond weight avg: =
DIVIDE (
SUMX (
FILTER ( Data, NOT ( Data[Category] IN { "String", "Stock" } ) ),
Data[Balance] * Data[Rate]
),
SUMX (
FILTER ( Data, NOT ( Data[Category] IN { "String", "Stock" } ) ),
Data[Balance]
)
)
Hi Jihwan-
Sorry to bother you but i have another question.
With the formula you helped with, what if i also have to Consider the HAS Rating = 1 and omit that of 0, even though there is value under Rate and Balance.
- Jihwan_Kim4 years ago
Super User
Hi,
Thank you for your message. Could you please try something like below whether it suits your requirement?
Only Bond weight avg: = DIVIDE ( SUMX ( FILTER ( Data, NOT ( Data[Category] IN { "String", "Stock" } ) && Data[HAS Rating] <> 0 ), Data[Balance] * Data[Rate] ), SUMX ( FILTER ( Data, NOT ( Data[Category] IN { "String", "Stock" } ) && Data[HAS Rating] <> 0 ), Data[Balance] ) )- Anonymous4 years agoNot applicable
Thank you for your prompt response, Jihwan.
- What if the first condition, i want to check for IS NOT NULL
(not sure of Power BI syntax).
- The second condition I would prefer = 1--then it will only be used if it's 1.
Thank you.
- Jihwan_Kim4 years ago
Super User
Hi,
Please try the below, or please share your sample pbix file with how your desired outcome looks like, and then I can try to come up with a more relevant solution.
Only Bond weight avg: = DIVIDE ( SUMX ( FILTER ( Data, NOT ( Data[Category] IN { "String", "Stock" } ) && Data[HAS Rating] = 1 ), Data[Balance] * Data[Rate] ), SUMX ( FILTER ( Data, NOT ( Data[Category] IN { "String", "Stock" } ) && Data[HAS Rating] = 1 ), Data[Balance] ) )