Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM. Register now.

Reply
HAMZA_07
Frequent Visitor

conditional formatting

Hello, I want help to color the first three rows with fixed colors, and the rest I want to use conditional formatting on them ....

as columns and not as rows

Capture d’écran 2022-12-29 094943.png

 

 

1 ACCEPTED SOLUTION

Hi @HAMZA_07 

 

On the columns Date, Net Positions, Long %, Short %, TOTAL and Index you apply the custom format has a value using the metric TOP Rows Format:

MFelix_0-1672339455679.pngMFelix_1-1672339473444.png

 

MFelix_2-1672339505480.png

On the columns for the long / short where you want to have the divergent you apply the divergent but instead of select the value of the column you select the measure Percentile variation (short or long depending).

MFelix_3-1672339587641.png

 

The blank values that are marked in my case has blue you need to set to yellow

 

 

 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



View solution in original post

7 REPLIES 7
MFelix
Super User
Super User

Hi @HAMZA_07 ,

 

For this you need to do some advance editing of the condittional formating this also depends on how you want to format the rows below.

 

For the first 3 lines create a metric similar to this:

TOP ROWS FORMATTING = IF(SELECTEDVALUE('Table (2)'[Index]) <=3 , "#118DFF")

 

This need to be used on all your columns has condittional formatting.

 

For the Long and Short depends on how you want to do the conditional formatting if it's by the diverging colours you need to add the following two metrics for each column:

 

percentile long =
IF (
    SELECTEDVALUE ( 'Table (2)'[Index] ) > 3,
    CALCULATE (
        PERCENTILE.EXC ( 'Table (2)'[Long], 0.5 ),
        FILTER ( ALL ( 'Table (2)' ), 'Table (2)'[Index] > 3 )
    )
)


Percentile_Long_Variation =
IF (
    SELECTEDVALUE ( 'Table (2)'[Index] ) > 3,
    SUM ( 'Table (2)'[Long] ) - [percentile long]
)

 

Now use this has the condittional formatting of the long column:

MFelix_0-1672316198966.png

Be aware that you need to select the specific colour for empty values

 

If the Long/Short has specific rules the you need to change the percentile to the specific rules using a swich statment:

 

I have created the following rule for short:

Format Short = 
SWITCH( TRUE(),
    SELECTEDVALUE ( 'Table (2)'[Index] ) <= 3, "#118DFF",
    SUM('Table (2)'[Short]) <= 11000, "Green",
    SUM('Table (2)'[Short]) <= 14000, "Red",
    SUM('Table (2)'[Short]) <= 99000, "BLue"
)

 

MFelix_2-1672316525543.png

 

On the example above I only formated the Date , long short and net positions but you can do it for all the columns.

 

 

 

 

 

 

 

 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Thank you for your reply, but I did not understand how to apply the new metric... I want the first three rows to be like what you applied in a picture, but in yellow color... and the columns like the picture below

 

Capture d’écran 2022-12-29 171617.png

 

Hi @HAMZA_07 

 

On the columns Date, Net Positions, Long %, Short %, TOTAL and Index you apply the custom format has a value using the metric TOP Rows Format:

MFelix_0-1672339455679.pngMFelix_1-1672339473444.png

 

MFelix_2-1672339505480.png

On the columns for the long / short where you want to have the divergent you apply the divergent but instead of select the value of the column you select the measure Percentile variation (short or long depending).

MFelix_3-1672339587641.png

 

The blank values that are marked in my case has blue you need to set to yellow

 

 

 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Brilliant trick. Using a percentage column you made it read it's empty . thank you 😊

Did my solution worked?

 

You marked your answer has the solution. Is that correct? 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Sorry I fixed it. Thank you

MAwwad
Solution Sage
Solution Sage

 

To color the first three rows with fixed colors and use conditional formatting on the rest of the rows in a Power BI table, you can use the following steps:

  1. Create a new column in your table that assigns a fixed color to the first three rows and a default color to the rest. You can do this using a calculated column with a formula similar to the following:

     

    Copy code
    Fixed Color = IF ( RANKX ( ALL ( 'Table' ), [Column] ) <= 3, SWITCH ( RANKX ( ALL ( 'Table' ), [Column] ), 1, "#FF0000", 2, "#00FF00", 3, "#0000FF", "#FFFFFF" ), "#FFFFFF" )
     

    This formula uses the RANKX function to assign a rank to each row based on the value of the "Column" field, and then uses the SWITCH function to assign a fixed color to the first three ranks and a default color to the rest. You can adjust the colors as needed by modifying the values in the SWITCH function.

    1. Go to the "Format" tab for the table visual and click on the "Conditional formatting" button in the "Data colors" section.

    2. In the "Conditional formatting" window, select the "Field" that you want to use for the conditional formatting, and then set the "Format by" option to "Color scales".

    3. In the "Color scales" section, select the default color that you want to use for the rest of the rows.

    4. In the "Data colors" section, set the "Data colors" option to "Fixed" and then select the "Fixed color" column that you created in step 1.

    5. Click the "OK" button to apply the formatting to the table.

Helpful resources

Announcements
October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Kudoed Authors