Forum Discussion
Calculated column or measure depending on parameter
Hi 123abc ,
Power BI does not allow me to add the measure to the Legend field.
You're correct; Power BI does not allow measures to be placed directly in the Legend field of a chart visualization. To achieve the desired result where you can classify the errors into faulty (1) or non-faulty (0) and visualize the proportions in a pie chart, you can follow these steps:
Create a new column in your data model that calculates the classification based on the tolerance value. This column will be a calculated column, which is static but is necessary to achieve this specific requirement. You can create it using DAX in Power BI's Data View:
Classification = IF(Table1[err] > [Tolerance], 1, 0)
Here, [Tolerance] should be replaced with the parameter or slicer that allows the user to set the tolerance value.
Next, create a measure to calculate the count of faulty and non-faulty parts. This measure will use the calculated column you created in the previous step:
Faulty Count = SUMX(Table1, [Classification])
Non-Faulty Count = COUNTROWS(Table1) - [Faulty Count]
Finally, create a pie chart visualization. Place the "Faulty Count" measure in the Values field and "Non-Faulty Count" measure in the Values field. You can also add a legend to the chart to distinguish between faulty and non-faulty.
Now, when the user changes the tolerance value using a slicer or parameter, the calculated column will dynamically update based on the tolerance value, and the pie chart will display the relative proportions of faulty vs. non-faulty parts based on the classification.
If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly.
In case there is still a problem, please feel free and explain your issue in detail, It will be my pleasure to assist you in any way I can.