Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Report Design
Message Icon Topic: Q: Conditional background color in Crosstab totals Post Reply Post New Topic
Author Message
bcgoh
Newbie
Newbie
Avatar

Joined: 16 Apr 2008
Online Status: Offline
Posts: 6
Quote bcgoh Replybullet Topic: Q: Conditional background color in Crosstab totals
     Posted: 16 Apr 2008 at 11:00pm

Hi,

I have this user requirement which I'm trying to cater for through a crosstab.

The format is as follows:

                 Facility1                          Facility2                         Facility3
                 Cat1   Cat 2   Cat 3 Ttl     Cat1   Cat 2   Cat 3 Ttl     Cat1   Cat 2   Cat 3 Ttl
Project1        5       4         0      9        1        2         3      6       5        0         5      10
Project2        0        0        0      0     

For each Ttl cell, the background colour is to be coloured according to this condition:

If Cat1 value is highest, colour is Green, else if Cat3 value is highest, colour is Red, , if Ttl is 0 or NULL then no colour is applied, for all other conditions, ie default, colour is Yellow.

Research shows that GridRowColumnValue and CurrentFieldValue can be used to colour a cell according to a condition, usually with the specific cell's value, but not if the outcome is dependent on other cells.

I have tried an alternative suggested by a co-worker:

  • sort the data by Facility, Project, Cat and add a counter variable to the details, with the condition to increment 1 of 3 variables depending on which category the record fits into and then comparing the value of these 3 variables to set a fourth var
  • this fourth var is used in the background formatting fomula for the ttl cells.

This solution is not quite working as all the total cells are displaying the same colour even though at record level, the variables are behaving as expected.

I have a feeling I'm still missing something about crosstabs behaviour. Now I am not sure what else I can try. Any help at all would be much appreciated! (I am a biz analyst who's not so savvy with the techy stuff, so please bear with me if I ask questions that may be simplistic or for which answers are usually obvious)

Thank you.



Edited by bcgoh - 16 Apr 2008 at 11:08pm
IP IP Logged
BrianBischof
Admin Group
Admin Group
Avatar

Joined: 09 Nov 2006
Online Status: Offline
Posts: 2458
Quote BrianBischof Replybullet Posted: 17 Apr 2008 at 1:41am
I talk about what happens behind the scenes with cross-tabs extensively in Chapter 13 of my Encyclopedia book and I give code samples for how to manipulate cross-tab data and formatting as well. Unfortunately, CR doesn't have the capability to do what you want. The problem you're running into isn't because one cell can't refer to another cell, but it's because cells can only look backwards (at the previous cells that have printed).

However, the trick around this (although this still may not fix your problem), is to use the functions you mentioned (GridRowColumnValue and CurrentFieldValue) to store the crosstab data into arrays. Then you can reference each element in the array and build logic comparing the elements to each other to set a cell's background color. Unfortunately, cross-tabs can only look at what has already been printed out. So column 2 can look at the values in column 1 (via the array I mentioned), and column 3 could look at col2 or col1. But column 1 can't look at data in column 2 (because it hasn't been printed yet).

I hope this helps clear things up. Again, you still may not be able to do what you need to do, but hopefully you have a better understanding of what is going on and maybe this will help you with future cross-tab questions.

You can find out more about my books and get lots of sample code for storing cross-tab data into arrays and using that to manipulate its formatting at Amazon.com or reading the Crystal Reports eBooks online.


Edited by BrianBischof - 17 Apr 2008 at 1:41am
Please support the forum! Tell others by linking to it on your blog or website:<a href="http://www.crystalreportsbook.com/forum/">Crystal Reports Forum</a>
IP IP Logged
bcgoh
Newbie
Newbie
Avatar

Joined: 16 Apr 2008
Online Status: Offline
Posts: 6
Quote bcgoh Replybullet Posted: 17 Apr 2008 at 10:36pm
Thank you very much responding and for the info. I will look into it. Smile
IP IP Logged
bcgoh
Newbie
Newbie
Avatar

Joined: 16 Apr 2008
Online Status: Offline
Posts: 6
Quote bcgoh Replybullet Posted: 12 May 2008 at 8:12pm
Hi,
Thought I'd post an update about the solution I'm using here for anyone interested:
 
In each crosstab cell, more than 1 field can be added for display or other uses.
 
So I added the Mode summary function as an additional field (which is suppressed) to each crosstab cell, and used a global variable to pass the mode of the group of data being evaluated to the corresponding Totals field and then use the mode value to determine the background colour to use.
 
It works fine. But now I'm facing another problem: in cases where the mode is shared by 2 categories, user wants the Totals background colour to assume the colour for the worse category, Cat1 being the best and Cat3 being the worst. EG if Cat2 and Cat3 both have the mode, then the background colour should be Red. Currently, the background colour is behaving in the opposite way. Any ideas how to provide prioritisation?
 
Thanks.
IP IP Logged
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum