Forum Discussion
Iteration 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 should say that on each review id, if (attribute = compliance, and score =0 or attribute = image and score =0 ) so all the scores of all attributes within that review id must equal 0 regardless of scores of 100
3- If the above condition is False, so if the score =100, sum the weight otherwise give 0
4- The column weight is in another dimension table
Sample table
| Review ID | Attribute | Score | Weight |
| 1 | Validation | 100 | 10 |
| 1 | Compliance | 100 | 30 |
| 1 | Image | 100 | 30 |
| 1 | Knowledge | 0 | 10 |
| 1 | Language | 0 | 10 |
| 1 | Accuracy | 100 | 10 |
| 2 | Validation | 100 | 10 |
| 2 | Compliance | 0 | 30 |
| 2 | Image | 100 | 30 |
| 2 | Knowledge | 0 | 10 |
| 2 | Language | 100 | 10 |
| 2 | Accuracy | 0 | 10 |
| 3 | Validation | 0 | 10 |
| 3 | Compliance | 0 | 30 |
| 3 | Image | 0 | 30 |
| 3 | Knowledge | 100 | 10 |
| 3 | Language | 100 | 10 |
| 3 | Accuracy | 0 | 10 |
| 4 | Validation | 100 | 10 |
| 4 | Compliance | 100 | 30 |
| 4 | Image | 100 | 30 |
| 4 | Knowledge | 100 | 10 |
| 4 | Language | 100 | 10 |
| 4 | Accuracy | 100 | 10 |
Desired result
| Review ID | Overall score | Weight | Score % |
| 1 | 80 | 100 | 80% |
| 2 | 0 | 100 | 0% |
| 3 | 0 | 100 | 0% |
| 4 | 100 | 100 | 100% |
| Total | 180 | 400 | 45% |
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] )
28 Replies
- tamerj1Community Champion
Khalefa
Please refer to attached sample file with the final solution.Weighted Score = SUMX ( 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 ) ) )Total Weight = SUMX ( VALUES ( 'Fact'[Review ID] ), SUMX ( CALCULATETABLE ( 'Fact' ), RELATED ( Dim_Attribute[Weight] ) ) )% Score = DIVIDE ( [Weighted Score], [Total Weight] )- KhalefaHelper I
tamerj1 thanks a lot, it works but if you don't mind, i need to add a small part which is:-
need to keep the condition of ( Compliance and Image ) active even if filtered by the slicer on the category.
by other means the condition must be applied even if i filtered by category3 ( which doesn't contain either compliance or image )
- tamerj1Community Champion
- CNENFRNLCommunity Champion
- v-yueyunzh-msftCommunity Support
Hi , Khalefa
I see that the CNENFRNL have been realized in his dax. But for your "another part, the weight column is in a dimension table with a unique list of attributes". But what dimension table 's structure in your side?
So is there a relationship between your dimension table and your sample data?
Can you provide your original table structure? For example, provide your dimension table in the form of a table?Thank you for your time and sharing, and thank you for your support and understanding of PowerBI!
Best Regards,
Aniya Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly
- KhalefaHelper I
the weight column is in a dimension table with a unique list of attributes
- tamerj1Community Champion
Hi Khalefa
Please refer to attached sample file with the solution (2 options)% Score = AVERAGEX ( VALUES ( Scores[Review ID] ), IF ( 0 IN CALCULATETABLE ( VALUES ( Scores[Score] ), Scores[Attribute] IN { "Compliance", "Image" } ), 0, SUMX ( CALCULATETABLE ( Scores ), Scores[Score] * RELATED ( Weights[Weight] ) / 100 ) / 100 ) )% Score2 = AVERAGEX ( VALUES ( Scores[Review ID] ), VAR T1 = CALCULATETABLE ( Scores ) RETURN IF ( ISEMPTY ( FILTER ( T1, Scores[Attribute] IN { "Compliance", "Image" } && Scores[Score] = 0 ) ), SUMX ( T1, Scores[Score] * RELATED ( Weights[Weight] ) / 100 ) / 100, 0 ) ) - KhalefaHelper I
Just a simple question, How can I add the PBiX file
- KhalefaHelper I
i just need to upload the model sample to be clear enough
- KhalefaHelper I
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 granularityhttps://drive.google.com/drive/folders/1Zkd_6sS582BE8NfHxITV1Gku4njHsk4A?usp=sharing
- tamerj1Community Champion
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 ) )
- KhalefaHelper I
tamerj1
the results should be as followtotal weighted score (145 ) / total weight (400)
Sumx output should be divided by total weight not just 100
Review ID Site Channel Attribute Score Weight Weighted score 1 Site1 Call Validation 100 15 15 1 Site1 Call Compliance 100 0 0 1 Site1 Call Image 100 0 0 1 Site1 Call Knowledge 0 40 0 1 Site1 Call Language 0 15 0 1 Site1 Call Accuracy 100 30 30 2 Site1 Call Validation 100 15 0 2 Site1 Call Compliance 0 0 0 2 Site1 Call Image 100 0 0 2 Site1 Call Knowledge 0 40 0 2 Site1 Call Language 100 15 0 2 Site1 Call Accuracy 0 30 0 3 Site2 Chat Validation 0 15 0 3 Site2 Chat Compliance 0 0 0 3 Site2 Chat Image 0 0 0 3 Site2 Chat Knowledge 100 40 0 3 Site2 Chat Language 100 15 0 3 Site2 Chat Accuracy 0 30 0 4 Site2 Chat Validation 100 15 15 4 Site2 Chat Compliance 100 0 0 4 Site2 Chat Image 100 0 0 4 Site2 Chat Knowledge 100 40 40 4 Site2 Chat Language 100 15 15 4 Site2 Chat Accuracy 100 30 30