Forum Discussion
Iteration with multiple column conditions
- 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] )
I have added here the model for more visibility:-
1- weight column is in a dim table
2- I need to use all the dim to filter the fact
3- the dax should consider that if attributes of Compliance or image are zero so all attributes of that review ID are zero other wise sum score * weight at the review level granularity
https://drive.google.com/drive/folders/1Zkd_6sS582BE8NfHxITV1Gku4njHsk4A?usp=sharing
Hi 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
)
)
- Khalefa3 years ago
Helper I
tamerj1 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