Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
I need to color the font and background of a measure based on the same conditions.
I created a new column to use for the background conditional format.
I don't understand why the syntax works for the 1st column, but not the 2nd column.
Any idea how I remedy the circular dependency error?
Solved! Go to Solution.
@kekepania0529 You're using a Measure inside a Calculated column, which adds the CALCULATE function to your calculated column.
Add CALCLULATE( [measure], ALLEXCEPT(Table, Table[Key])) anywhere you reference a measure.
Do this in all your calculated columns anywhere you have a measure, and click into existing Calculated columns and hit Enter to force them to re-evaluate (Circular Reference errors don't fix on their own).
This post explains it well: https://www.sqlbi.com/articles/avoiding-circular-dependency-errors-in-dax/
But my recap of it is:
The CALCULATE function converts ROW context into FILTER context, which means that even though you don't see it, every single column in your table that already exists is written (in invisible ink shall we say??? 🤣 ) in your formula.
So, you can create the first column with no issues, let's say it's called [Color Font] and the formula is simple
[Color Font] = [Measure]
Your table now looks like this:
Category | Product | Color Font |
Fruit | Pear | Green |
Fruit | Orange | Orange |
Vegetable | Carrot | Orange |
Vegetable | Pepper | Green |
The [Color Font] column uses a Measure, so that has an implicit CALCULATE function wrapped around the measure, which adds the following code, different for each row:
Category | Product | Color Font | Color Font Code |
Fruit | Pear | Green | [Color Font] = CALCULATE( [Measure], Table[Category] = "Fruit", Table[Product] = "Pear") |
Fruit | Orange | Orange | [Color Font] = CALCULATE( [Measure], Table[Category] = "Fruit", Table[Product] = "Orange") |
Vegetable | Carrot | Orange | [Color Font] = CALCULATE( [Measure], Table[Category] = "Vegetable", Table[Product] = "Carrot") |
Vegetable | Pepper | Green | [Color Font] = CALCULATE( [Measure], Table[Category] = "Vegetable", Table[Product] = "Pepper") |
But now you want to add a second column, [Color Background]. By adding another column, the code of our original column will change, and so will the [Color Background] code, and you'll see that they both try to reference each other, thus resulting in Circular Reference Error:
Category | Product | Color Font | Color Background | Color Font Code | Color Background Code |
Fruit | Pear | Green | [Color Font] = CALCULATE( [Measure], Table[Category] = "Fruit", Table[Product] = "Pear", Table[Color Background] = "Value Color Background") | [Color Background] = CALCULATE( [Measure], Table[Category] = "Fruit", Table[Product] = "Pear", Table[Color Font] = "Value Color Font") | |
Fruit | Orange | Orange | [Color Font] = CALCULATE( [Measure], Table[Category] = "Fruit", Table[Product] = "Orange", Table[Color Background] = "Value Color Background") | [Color Background] = CALCULATE( [Measure], Table[Category] = "Fruit", Table[Product] = "Orange", Table[Color Font] = "Value Color Font") | |
Vegetable | Carrot | Orange | [Color Font] = CALCULATE( [Measure], Table[Category] = "Vegetable", Table[Product] = "Carrot", Table[Color Background] = "Value Color Background") | [Color Background] = CALCULATE( [Measure], Table[Category] = "Vegetable", Table[Product] = "Carrot", Table[Color Font] = "Value Color Font") | |
Vegetable | Pepper | Green | [Color Font] = CALCULATE( [Measure], Table[Category] = "Vegetable", Table[Product] = "Pepper", Table[Color Background] = "Value Color Background") | [Color Background] = CALCULATE( [Measure], Table[Category] = "Vegetable", Table[Product] = "Pepper", Table[Color Font] = "Value Color Font") |
To fix it, we could use the Unique column identifier (in this example not ideal but the Product name). So if we rewrite our [Color Font] column as:
[Color Font] = CALCULATE([Measure], ALLEXCEPT(Table, Table[Product]) )
and do the same for Color Background, then we'll get rid of the Circular Dependency.
Copying DAX from this post? Click here for a hack to quickly replace it with your own table names
Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C
I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com
@kekepania0529 As a side note, could you create this as a measure instead of a Calculated column? That would also fix the problem... Just need to figure out what context to evaluate within in that case, so you might find my original suggestion easier.
Copying DAX from this post? Click here for a hack to quickly replace it with your own table names
Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C
I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com
@kekepania0529 You're using a Measure inside a Calculated column, which adds the CALCULATE function to your calculated column.
Add CALCLULATE( [measure], ALLEXCEPT(Table, Table[Key])) anywhere you reference a measure.
Do this in all your calculated columns anywhere you have a measure, and click into existing Calculated columns and hit Enter to force them to re-evaluate (Circular Reference errors don't fix on their own).
This post explains it well: https://www.sqlbi.com/articles/avoiding-circular-dependency-errors-in-dax/
But my recap of it is:
The CALCULATE function converts ROW context into FILTER context, which means that even though you don't see it, every single column in your table that already exists is written (in invisible ink shall we say??? 🤣 ) in your formula.
So, you can create the first column with no issues, let's say it's called [Color Font] and the formula is simple
[Color Font] = [Measure]
Your table now looks like this:
Category | Product | Color Font |
Fruit | Pear | Green |
Fruit | Orange | Orange |
Vegetable | Carrot | Orange |
Vegetable | Pepper | Green |
The [Color Font] column uses a Measure, so that has an implicit CALCULATE function wrapped around the measure, which adds the following code, different for each row:
Category | Product | Color Font | Color Font Code |
Fruit | Pear | Green | [Color Font] = CALCULATE( [Measure], Table[Category] = "Fruit", Table[Product] = "Pear") |
Fruit | Orange | Orange | [Color Font] = CALCULATE( [Measure], Table[Category] = "Fruit", Table[Product] = "Orange") |
Vegetable | Carrot | Orange | [Color Font] = CALCULATE( [Measure], Table[Category] = "Vegetable", Table[Product] = "Carrot") |
Vegetable | Pepper | Green | [Color Font] = CALCULATE( [Measure], Table[Category] = "Vegetable", Table[Product] = "Pepper") |
But now you want to add a second column, [Color Background]. By adding another column, the code of our original column will change, and so will the [Color Background] code, and you'll see that they both try to reference each other, thus resulting in Circular Reference Error:
Category | Product | Color Font | Color Background | Color Font Code | Color Background Code |
Fruit | Pear | Green | [Color Font] = CALCULATE( [Measure], Table[Category] = "Fruit", Table[Product] = "Pear", Table[Color Background] = "Value Color Background") | [Color Background] = CALCULATE( [Measure], Table[Category] = "Fruit", Table[Product] = "Pear", Table[Color Font] = "Value Color Font") | |
Fruit | Orange | Orange | [Color Font] = CALCULATE( [Measure], Table[Category] = "Fruit", Table[Product] = "Orange", Table[Color Background] = "Value Color Background") | [Color Background] = CALCULATE( [Measure], Table[Category] = "Fruit", Table[Product] = "Orange", Table[Color Font] = "Value Color Font") | |
Vegetable | Carrot | Orange | [Color Font] = CALCULATE( [Measure], Table[Category] = "Vegetable", Table[Product] = "Carrot", Table[Color Background] = "Value Color Background") | [Color Background] = CALCULATE( [Measure], Table[Category] = "Vegetable", Table[Product] = "Carrot", Table[Color Font] = "Value Color Font") | |
Vegetable | Pepper | Green | [Color Font] = CALCULATE( [Measure], Table[Category] = "Vegetable", Table[Product] = "Pepper", Table[Color Background] = "Value Color Background") | [Color Background] = CALCULATE( [Measure], Table[Category] = "Vegetable", Table[Product] = "Pepper", Table[Color Font] = "Value Color Font") |
To fix it, we could use the Unique column identifier (in this example not ideal but the Product name). So if we rewrite our [Color Font] column as:
[Color Font] = CALCULATE([Measure], ALLEXCEPT(Table, Table[Product]) )
and do the same for Color Background, then we'll get rid of the Circular Dependency.
Copying DAX from this post? Click here for a hack to quickly replace it with your own table names
Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C
I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
109 | |
98 | |
77 | |
66 | |
54 |
User | Count |
---|---|
144 | |
104 | |
100 | |
86 | |
64 |