Forum Discussion
Apply conditional formatting to a visual calculation
- Anonymous1 year ago
Hi Anonymous,
Thank you for reaching out to the Microsoft Fabric Forum Community.
Please try creating a single visual calculation measure for Variance and apply conditional formatting using the following DAX query:
Color =
VAR Variance = [Actual Cost] - [Standard Cost]
RETURN
IF (Variance >= 0, "Green", "Red")If the issue continues, feel free to contact us. We are here to assist you.
Best regards,
Prasanna Kumar
Hi Anonymous ,
Yes, it is possible to apply conditional formatting, specifically red and green icons, to a visual calculation in Power BI. This functionality allows for more dynamic and visually intuitive reports directly within a visual, avoiding the need for complex DAX measures when dealing with intricate data models. You can achieve your goal of displaying icons based on whether your "Variance" calculation is positive or negative.
First, you would create your "Variance" visual calculation within your table or matrix. This is done by selecting the visual and adding a new visual calculation with a formula that subtracts the standard cost from the actual cost.
Variance = [Actual Cost] - [Standard Cost]
Once the visual calculation is created, you can apply the icon-based conditional formatting. In the "Visualizations" pane, right-click on your "Variance" visual calculation field, navigate to "Conditional formatting," and select "Icons." In the dialog box that appears, you will define the rules. For a negative variance, you can set a rule where if the value is less than 0, a red icon is displayed. You would then add a new rule for a positive variance, stating that if the value is greater than or equal to 0, a green icon should be used. After applying these rules, your visual will automatically show the corresponding icons next to your variance figures.
An alternative approach is to create a second visual calculation dedicated solely to generating an indicator for the icon. This keeps the numerical variance and the visual icon in separate columns. You could use a SWITCH function to output a text value like "Red" or "Green" based on the variance.
Variance Icon =
SWITCH(
TRUE(),
[Variance] < 0, "Red",
[Variance] > 0, "Green",
"Yellow"
)
With this "Variance Icon" calculation, you would then apply conditional formatting to it. Instead of using rules, you would select "Field value" as the format style and base it on the "Variance Icon" field itself. This method provides explicit control over the logic and presentation of your visual indicators, streamlining the process of creating insightful reports.
Best regards,
- Anonymous1 year agoNot applicable
Hi, thank you however, i am not given the option to select conditional formatting when it is a visual calculation