Forum Discussion
Khalefa
Helper I
3 years agoIteration with multiple column conditions
Hi team Need support in the below a measure to calculate the overall attribute score on the review ID granularity considering the below:- 1- There are 6 attributes in each review id 2- The DAX sh...
- 3 years ago
Hi Khalefa
Please refer to attached amended sample fileWeighted Score = SUMX ( VALUES ( 'Fact'[Review ID] ), IF ( 0 IN CALCULATETABLE ( VALUES ( 'Fact'[Score] ), ALL ( Dim_Attribute[Attribute] ), Dim_Attribute[Attribute] IN { "Compliance", "Image" } ), 0, SUMX ( CALCULATETABLE ( 'Fact' ), 'Fact'[Score] * RELATED ( Dim_Attribute[Weight] ) / 100 ) ) )Total Weight = SUMX ( VALUES ( 'Fact'[Review ID] ), SUMX ( CALCULATETABLE ( 'Fact' ), RELATED ( Dim_Attribute[Weight] ) ) )% Score = DIVIDE ( [Weighted Score], [Total Weight] )
tamerj1
Community Champion
3 years agoHi Khalefa
I hope this is what you're looking for. Please refer to attached sample file.
% Score =
AVERAGEX (
VALUES ( 'Fact'[Review ID] ),
IF (
0
IN CALCULATETABLE (
VALUES ( 'Fact'[Score] ),
Dim_Attribute[Attribute] IN { "Compliance", "Image" }
),
0,
SUMX ( CALCULATETABLE ( 'Fact' ), 'Fact'[Score] * RELATED ( Dim_Attribute[Weight] ) / 100 ) / 100
)
)
Khalefa
Helper I
3 years agotamerj1 can i ask why did you use calculatetable after sumx rather than just sumx
on the other side, you referred to attribute from dim table rahter than attribute from fact. will this matter ?
Thanks for your patiance
- tamerj13 years ago
Community Champion
CALCULATETABLE is required for context transition otherwise 'Fact' will be filtered only as per the original filter context filter context i.e. the filters on the visual, slicers, filter pane etc.. while we need the table filtered by the currently iterated Review ID.
Regarding your 2nd question, the answer is no, it makes no difference