Forum Discussion
Conditional format asset returns based upon weight Averages
- 5 years ago
Hi Anonymous
If the calculations is correct then for the condittional formatting use the following measure:
Conditional_Formatting = VAR temp_table = SUMMARIZE ( ALL ( Assets[Asset Name], Assets[Asset Type], Assets[Attribute], Assets[Value] ), Assets[Attribute], "Total Value", [Values] ) RETURN SWITCH ( TRUE (), SELECTEDVALUE ( Period[Period] ) = "Value £", BLANK (), [Values] > SUMX ( temp_table, [Total Value] ) * 1.2, "Green", [Values] < SUMX ( temp_table, [Total Value] ) * 0.8, "Red" )Don't forget to mark the correct answer to help others.
PBIX file attach.
- 5 years ago
Hi Anonymous ,
Redo the measure to:
Conditional_Formatting = VAR temp_table = SUMMARIZE ( ALLSELECTED ( Assets[Asset Type], Assets[Attribute], Assets[Asset Name], Assets[Value] ), Assets[Attribute], Assets[Asset Type], "Total Value", [Values] ) VAR AssetTypeTotal = SUMX ( FILTER ( temp_table, Assets[Asset Type] = SELECTEDVALUE ( Assets[Asset Type] ) ), [Total Value] ) RETURN IF ( ISFILTERED ( Assets[Asset Name] ), SWITCH ( TRUE (), SELECTEDVALUE ( Period[Period] ) = "Value £", BLANK (), [Values] > AssetTypeTotal * 1.2, "Green", [Values] < AssetTypeTotal * 0.8, "Red" ) )
Hi Anonymous ,
You can do the following:
- Unpivot the period columns on your data
- Create a new table using the following code:
Period = UNION(DISTINCT('Assets'[Attribute]); {"Value £"})
- Create the following measure:
Values =
IF (
SELECTEDVALUE ( 'Period'[Attribute] ) = "Value £";
SUMX ( VALUES ( 'Assets'[Asset Name] ); AVERAGE ( 'Assets'[Value £] ) );
CALCULATE (
SUMX ( 'Assets'; 'Assets'[Value] * 'Assets'[Value £] )
/ SUM ( 'Assets'[Value £] );
FILTER (
ALLSELECTED ( 'Assets'[Attribute] );
'Assets'[Attribute] = SELECTEDVALUE ( 'Period'[Attribute] )
)
)
)
- Configure your matrix in the following way:
- Rows:
- Asset Type
- Asset Name
- Columns
- Periods from the Period table
- Values
- Values measure
- Rows:
Result below and in attach PBIX file:
I have only one question regarding the last line of the Weight average on the last line how are you calculating the values since all the calculations I have tried don't give the same value.
Hi Miguel
Many thanks for a super quick and comprehensive response I will download and try out the attached file.
The last lien of weighted averages is just a weighted average of the subtotals to give an overal average. I t should come to the same answer as taking all the individual line items.
ie
(Sub total Shares * Total value Shares + sub Total Bonds * Total Value Bond + sub Total Other * Total Value Other)/ Total Value