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] )
tamerj1
the results should be as follow
total 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 |
- tamerj13 years ago
Community Champion
145/400 = 36% and this is exactly the result obtained at the total level. Am I missing something?
- Khalefa3 years ago
Helper I
I just want to get the total score from your solution without percentage and another DAX for the total weight. this is what I meant.
- v-yueyunzh-msft3 years ago
Community Support
Hi , Khalefa
Thanks for your quick response and your sample .pbix file to us!
Here are the steps you can refer to :
(1)We can create a calculated column in 'Fact' Table:Weighted score = var _cur_ID = [Review ID] var _t =SELECTCOLUMNS( FILTER('Fact' , 'Fact'[Review ID] = _cur_ID && 'Fact'[Attribute] in {"Compliance","Image"}) , "Score",[Score]) var _weight = RELATED('Dim_Attribute'[Weight]) var _cur_sore = [Score] return IF( {0} in _t , 0 , IF(_cur_sore=0,0, _weight))(2)Then we can create these measures:
Total Weight = SUMX( VALUES('Fact'), RELATED('Dim_Attribute'[Weight]))Total Weight 2 = SUMX( ALL('Fact'), RELATED('Dim_Attribute'[Weight]))Score % = SUM('Fact'[Weighted score]) / [Total Weight](3)Then we can put the fieds we need on the visual and we can meet your need:
If this method does not meet your needs, you can provide us with your special sample data and the desired output sample data in the form of tables, so that we can better help you solve the problem.
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