The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredCompete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.
We are working on a BI with multiple tables. There are 2 separate tables as seen below. The predefined values are stored in one table and actual values stored in another. We are using actual values in the BI as a matrix table. We want to highlight the font in red only if the actual parameter is not in range of predefined value. PLease advise how we can achieve the same.
Predefined | Actual values | |||||||||
Product | Parameters | Value1 | value2 | Product | Date | Parameters | Value | |||
TV | a | 1 | 4 | TV | 05-02-2020 | a | 3 | |||
b | 5 | 9 | b | 4 | ||||||
c | 15 | 20 | c | 25 | ||||||
Mobile | a | 5 | 10 | Mobile | 20-02-2020 | a | 3 | |||
b | 4 | 9 | b | 4 | ||||||
c | 15 | 20 | c | 25 | ||||||
Laptop | a | 3 | 7 | Laptop | 05-02-2020 | a | 3 | |||
b | 5 | 9 | b | 4 | ||||||
c | 18 | 25 | c | 25 |
Solved! Go to Solution.
If there is no direct relationship or connection between the two tables based on parameters, you can still achieve conditional font color formatting by using a DAX (Data Analysis Expressions) measure that calculates whether the actual values are within the predefined ranges for each product and parameter combination. Here's how you can modify the approach:
IsValueWithinRange =
VAR CurrentProduct = 'Actual values'[Product]
VAR CurrentParameter = 'Actual values'[Parameters]
VAR ActualValue = 'Actual values'[Value]
VAR PredefinedValue1 = CALCULATE(MAX('Predefined'[Value1]),
FILTER('Predefined', 'Predefined'[Product] = CurrentProduct && 'Predefined'[Parameters] = CurrentParameter))
VAR PredefinedValue2 = CALCULATE(MAX('Predefined'[Value2]),
FILTER('Predefined', 'Predefined'[Product] = CurrentProduct && 'Predefined'[Parameters] = CurrentParameter))
RETURN
IF(ActualValue >= PredefinedValue1 && ActualValue <= PredefinedValue2, "Green", "Red")
This measure calculates whether the actual value is within the predefined range for the current product and parameter combination. It returns "Green" if it is within the range and "Red" if it's not.
Once you've created the DAX measure, you can use it in your matrix table to conditionally format the font color. Here's how you can do this:
Repeat steps 1 and 2 for each cell or text where you want to apply the conditional font color formatting in your matrix table.
This approach uses a DAX measure to dynamically calculate whether the actual values are within the predefined ranges for each product and parameter combination. It doesn't rely on a direct relationship between the two tables based on parameters but instead leverages DAX calculations to determine the font color based on the data in both tables.
Hi,
Thanks! Can you please explain the data modelling part? Now both the tables are connected only by product details. There is no connection between the parameters
If there is no direct relationship or connection between the two tables based on parameters, you can still achieve conditional font color formatting by using a DAX (Data Analysis Expressions) measure that calculates whether the actual values are within the predefined ranges for each product and parameter combination. Here's how you can modify the approach:
IsValueWithinRange =
VAR CurrentProduct = 'Actual values'[Product]
VAR CurrentParameter = 'Actual values'[Parameters]
VAR ActualValue = 'Actual values'[Value]
VAR PredefinedValue1 = CALCULATE(MAX('Predefined'[Value1]),
FILTER('Predefined', 'Predefined'[Product] = CurrentProduct && 'Predefined'[Parameters] = CurrentParameter))
VAR PredefinedValue2 = CALCULATE(MAX('Predefined'[Value2]),
FILTER('Predefined', 'Predefined'[Product] = CurrentProduct && 'Predefined'[Parameters] = CurrentParameter))
RETURN
IF(ActualValue >= PredefinedValue1 && ActualValue <= PredefinedValue2, "Green", "Red")
This measure calculates whether the actual value is within the predefined range for the current product and parameter combination. It returns "Green" if it is within the range and "Red" if it's not.
Once you've created the DAX measure, you can use it in your matrix table to conditionally format the font color. Here's how you can do this:
Repeat steps 1 and 2 for each cell or text where you want to apply the conditional font color formatting in your matrix table.
This approach uses a DAX measure to dynamically calculate whether the actual values are within the predefined ranges for each product and parameter combination. It doesn't rely on a direct relationship between the two tables based on parameters but instead leverages DAX calculations to determine the font color based on the data in both tables.
Hi @123abc ,
In additional to the above condition, for some fileds, the condition is taking from another field in parameter. For ex, for parameter B for TV, the red highlight is based on parameter D value of TV and which check if D is within Predefined values
Hi @123abc ,
Did you get a chance to check this? After implemeting the above case, we found out that for a few parameters, the colour code is based on other parameters. For example, for Mobile parameter A is coloured red if value of parameter B is not in range of predefined value B. I tried by myself to do this but unable to do it. Could you please assist?
Thank you very much! It worked!!
If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly.
To highlight the font in red for actual values that are not in the range of predefined values in Power BI, you can use conditional formatting. Here's how you can achieve this:
Data Modeling: Ensure that both the "Predefined" table and the "Actual Values" table are loaded into Power BI, and there's a relationship between them. Specifically, make sure that there's a relationship between the "Product" and "Parameters" columns in both tables.
Create a Measure for Conditional Formatting: Create a measure that compares the actual value with the predefined range and returns a value that you can use for conditional formatting. Here's an example measure that checks if the actual value is not within the predefined range:
NotInRange =
IF(
NOT(ISFILTERED('Actual Values'[Value])) || -- Check if Value is selected
ISBLANK(SELECTEDVALUE('Actual Values'[Value])), -- Check if Value is blank
BLANK(), -- Return blank if not selected or blank
IF(
SELECTEDVALUE('Actual Values'[Value]) >= MIN('Predefined'[Value1]) &&
SELECTEDVALUE('Actual Values'[Value]) <= MAX('Predefined'[Value2]),
BLANK(), -- Within the range, return blank for no formatting
1 -- Outside the range, return 1 for formatting
)
)
This measure checks if the selected value is within the predefined range and returns 1 if it's not.
Apply Conditional Formatting: Now, apply conditional formatting to the matrix or table visual in your report. Follow these steps:
Test the Report: Now, when you view your report, the font color for actual values that are not within the predefined range will be red.
This approach uses DAX measures to calculate whether a value is within the predefined range and then applies conditional formatting based on the measure's result. Ensure that you have a proper data model and relationships set up between your tables for this to work effectively.