Forum Discussion
Conditional formatting works badly
- 8 years ago
Anonymous,
I tried to recreate your scenario but was not able to.
I am able to conditionally format the data as per your requirement even when connected in direct query mode
My Table Data is as follows
Year Month value Comp 2018 Apr 10 Comp2 2018 Apr 20 Comp2 2018 Apr 30 Comp2 2018 Mar 10 Comp1 2018 Mar 20 Comp1 2018 Mar 30 Comp1 2018 May 10 Comp3 2018 May 20 Comp3 2018 May 30 Comp3 In the above table, the column "Comp" is a calculated column and the code is as follows (Comp is created in Query Editor Window)
= Table.AddColumn(dbo_TestLoad, "Comp", each if [Month] = "Mar" then "Comp1" else if [Month] = "Apr" then "Comp2" else "Comp3")
Then I create another calculated Column "Column". This time I am creating this is Power BI Desktop where all the fields are visible
Column = IF(TestLoad[Comp] = "Comp1", 1, IF(TestLoad[Comp] = "Comp2", 2, 3))
The Above column has Data Type and Data Format as Whole Number
Below is my report output after conditional formattingReport Output
For your reference, my conditional formatting rules
Formatting by Rules
Anonymous,
I tried to recreate your scenario but was not able to.
I am able to conditionally format the data as per your requirement even when connected in direct query mode
My Table Data is as follows
| Year | Month | value | Comp |
| 2018 | Apr | 10 | Comp2 |
| 2018 | Apr | 20 | Comp2 |
| 2018 | Apr | 30 | Comp2 |
| 2018 | Mar | 10 | Comp1 |
| 2018 | Mar | 20 | Comp1 |
| 2018 | Mar | 30 | Comp1 |
| 2018 | May | 10 | Comp3 |
| 2018 | May | 20 | Comp3 |
| 2018 | May | 30 | Comp3 |
In the above table, the column "Comp" is a calculated column and the code is as follows (Comp is created in Query Editor Window)
= Table.AddColumn(dbo_TestLoad, "Comp", each if [Month] = "Mar" then "Comp1" else if [Month] = "Apr" then "Comp2" else "Comp3")
Then I create another calculated Column "Column". This time I am creating this is Power BI Desktop where all the fields are visible
Column = IF(TestLoad[Comp] = "Comp1", 1, IF(TestLoad[Comp] = "Comp2", 2, 3))
The Above column has Data Type and Data Format as Whole Number
Below is my report output after conditional formattingReport Output
For your reference, my conditional formatting rules
Formatting by Rules
It works! I don't know why I didn't think this way. I created my new column in Query Editor, I think it should be the same of your way, but it didn't.
Thank you very much!!