Search code examples
reporting-servicesssrs-2008rdlc

change colour of highest total column value in rdl report


how to highlighte highest number of a total column

In rdl report i am showing total column as sum aggregation, i want to highlighte highest of that total.


Solution

  • This is a generic answer that makes lots of assumptions. As you question does not contain enough info for a definitive answer but hopefully this will give you enough that you resolve your problem.

    To recreate this do the following (and then adapt to suit your specific situation)

    Create a new report.

    Add a datset and use the following query as the dataset query

    -- create some sample data
    DECLARE @t TABLE(Customer varchar(10), Product varchar(10), Quantity int)
    INSERT INTO @t VALUES 
    ('Dave', 'Hammer', 6), ('Dave', 'Saw', 6),('Dave', 'Hammer', 1),
    ('George', 'Drill', 3),('George', 'Hammer', 6),('George', 'Saw', 6),('George', 'Hammer', 1),
    ('Mary', 'Drill', 3),('Mary', 'Hammer', 6),
    ('Jane', 'Saw', 6),('Jane', 'Hammer', 1),('Jane', 'Drill', 3)
    
    -- return the sample data plus a total per customer
    SELECT *
            , CustomerTotal = SUM(Quantity) OVER(PARTITION BY Customer)
        FROM @t
    

    This give use the following results

    enter image description here

    Next add a Matrix control to the report. Drag the fields to the matrix as shown here enter image description here

    Customer to "Rows"; Product to "Columns"; Quantity to "Data"

    You should now have a matrix with some row and column groups shown underneath. next we need to add a total column so right-click the "Product" column group select "Add Total => After"

    enter image description here

    Finally, we need to test if the value in the total column matches the largest CustomerTotal in our dataset. If it does match then change the textbox color property to "Red".

    We can use this expression in the textbox color to do this..

    =IIF(
        Sum(Fields!Quantity.Value) = MAX(Fields!CustomerTotal.Value, "DataSet1"), 
        "Red",
        "Black")
    

    What this does is take the total quantity in the current scope (the entire row) and compare it to the highest CustomerTotal with the scope "Dataset1" which is the entire dataset. If the two match, set the vlue to "Red", else set it to "Black"

    With a bit of a tidy-up the final output looks like this.

    enter image description here