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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
E12345
Resolver II
Resolver II

Need to color record groups of the paginated report with alternate colors (Power BI Report Builder)

HI! 
I have a question about how to write an expression inside the "background" area of the Power BI Report Builder (for paginated reprots similar to SSRS) of the chart to highlight alternate ticket detail with alternating colors. Blow is my pictorial representation with some dummy data. For example, ticket number 1 needs to be grey, then ticket number 2 white, then ticket numbner 3 grey again. There may be multiple records per each ticket, so I need to somehow count when the ticket number changes and switch the color so th euser has easier time telling one ticket's details from another (all data is organized by ticket number). I am assuming MOD function needs to be used for this calculation. The data is eventually going to be exported to Excel, so I need it to be a part of the same table (no visible groupings should be intoduced, I am assuming - else it will break the "excel like" nature of the dataset. TY!

 

E12345_0-1725772039113.png

 

 

Same Data as text in case you need to copu and paste it:

Ticket_IDTicket_Descr
1first
1first
1first
2second
2second
3third
4fourth
4fourth
4fourth
5fifth
6sixth
6sixth
6sixth
6sixth
6sixth
7seventh
7seventh
8eightth

 

1 ACCEPTED SOLUTION

Hi @E12345 ,

I did a test in Report Builder.

vyilongmsft_0-1726045982652.png

Then you can try this code.

=IIF(Fields!Ticket_ID.Value Mod 2 <> 0, "Gray", "Transparent")

vyilongmsft_1-1726046041208.png

Finally you can get this result.

vyilongmsft_2-1726046083449.png

 

 

 

Best Regards

Yilong Zhou

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

9 REPLIES 9
v-yilong-msft
Community Support
Community Support

Hi @E12345 ,

I create a table as you mentioned.

vyilongmsft_0-1725936234193.png

Then I create a measure and here is the DAX code.

Color =
SWITCH (
    TRUE (),
    SELECTEDVALUE ( 'Table'[Ticket_ID] ) = 1, "#A9A9A9",
    SELECTEDVALUE ( 'Table'[Ticket_ID] ) = 3, "#A9A9A9",
    SELECTEDVALUE ( 'Table'[Ticket_ID] ) = 5, "#A9A9A9",
    SELECTEDVALUE ( 'Table'[Ticket_ID] ) = 7, "#A9A9A9",
    "#FFFFFF"
)

Next you can go to the Conditional Formatting and select background color.

vyilongmsft_1-1725936364277.png

vyilongmsft_2-1725936414163.png

You can do the same thing twice.

vyilongmsft_3-1725936462794.png

Finally you can get what you want.

vyilongmsft_4-1725936502388.png

 

 

 

Best Regards

Yilong Zhou

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi!
Thank you very much for trying to solve this problem. However, your solution is not the right one for me. I do not need a measure in Power BI, but I need a formula (VB) to place into the Power BI Report Builder application - into the background color of the details section. When I asked to add my sample dataset to the app, I meant you need to add it to "Power BI Report Builder" app, not to "Power BI Desktop" app ;). 

Also, your measure hard codes each ticket, but this is really only a sample data, there are throusands of "tickets" so a dynamic formula would be needed to figure out each new grouping. 

For your info, this is the envoronment for Power BI Report Builder. I use Dax as Query language, but inside the app still uses Visual basic. So, this question is for anyone who can work with Power BI Report Builder. 

Pasting a screenshot of the report - as you can see, this app is not the Power BI Desktop, it is an additional app for paginated reports building. 

E12345_0-1725980226250.png

 

Hi @E12345 ,

I did a test in Report Builder.

vyilongmsft_0-1726045982652.png

Then you can try this code.

=IIF(Fields!Ticket_ID.Value Mod 2 <> 0, "Gray", "Transparent")

vyilongmsft_1-1726046041208.png

Finally you can get this result.

vyilongmsft_2-1726046083449.png

 

 

 

Best Regards

Yilong Zhou

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Wowed! This line worked like a charm, and it is such a simple line, but I could not figure out the syntax! Thank you so much!!!! I changed the color to LightGrey

=IIF(Fields!Ticket_ID.Value Mod 2 <> 0, "LightGray", "Transparent")

 😉
A million thanks!

E12345_2-1726183726975.png

 

E12345_0-1726183338934.png

 

E12345
Resolver II
Resolver II

You can easily add the table I provided to the report to verify whether your code works... For some reason I am unable to find a solution, even when I grouped by Ticket ID (I keep getting an error or the groups of rows with the same ID are not highlighted properly). I will keep trying and if it works, will post my solution... So far no luck. Thank you for your help though. 

By the way, I figured out how to highlight alternate rows, but I need to highlight groups of rows, so it is not helping... This is the expression that I placed in the background area of the row that provides alternate colors:

=IIF(RowNumber(Nothing) MOD 2 = 0, "White", "LightGray")

E12345_0-1725909918608.png

 

E12345
Resolver II
Resolver II

if this is of any help - I tried this code but it did nto work... I need soemthing similar...

=IIF(RunningValue(Fields!Ticket_ID.Value, CountDistinct, "myDataSet") <> Previous(RunningValue(Fields!Ticket_ID.Value, CountDistinct, "myDataSet")), "LightGrey", "White")

Hi @E12345 - can you try below conditional formatting code.

 

=IIF(
MOD(
RunningValue(Fields!Ticket_ID.Value, CountDistinct, Nothing), 2
) = 0,
"White",
"LightGray"
)





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

Proud to be a Super User!





Your formula sounds like it should do the trick, but it does not work... Perhaps groupings are needed in addition to the formula? Could you please add the dataset to the Power BI Report Builder and try it yourself? (save it in Excel and add it as a datasource). I feel like you have the potential to solve it. TY! 😉

For some reason I got the error:

"The 'BackgroundColor' expression for the text box 'Ticket_ID' contains an error: [BC30201] Expression expected.
----------------------------
The definition of the report '' is invalid.
----------------------------
An error occurred during local report processing."

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

Feb2025 NL Carousel

Fabric Community Update - February 2025

Find out what's new and trending in the Fabric community.