Question

I've got this expression in a report:

=iif(
SUM(Fields!Amount.Value) >
    (
    SUM(iif
        (
        Fields!Date.Value >= DateAdd("d",-10,TODAY())
        ,Fields!Amount.Value
        ,CDbl(0)
        )) / 10
    )*2.0,
"Gold",
"Transparent"
)

It is controlling a table's text box background colour.

I was hoping it would change the cell to gold if the amount in the cell is twice, or more, than the 10 day average for that specific row.

The table shows 10 days of data and the dataset it uses has 60 days of data in it, so 10 day averages should be available.

Is the expression incorrect?

This is what it is currently creating - the two rows that are completely orange are obviously not what I want.

enter image description here

Was it helpful?

Solution

The issue is with the sum you are doing to create your average. It is really only summing the first number it encounters and then dividing by 10 and multiplying by 2. You need to change the scope of your sum to the entire dataset. Here's how I proved this out.

I took the second row of numbers in your table above as my example. Here's my query.

SELECT        '1/15/14' AS dt, 1 AS value
UNION
SELECT        '1/16/14' AS dt, 7 AS value
UNION
SELECT        '1/17/14' AS dt, 5 AS value
UNION
SELECT        '1/18/14' AS dt, 6 AS value
UNION
SELECT        '1/19/14' AS dt, 4 AS value
UNION
SELECT        '1/20/14' AS dt, 5 AS value
UNION
SELECT        '1/21/14' AS dt, 5 AS value
UNION
SELECT        '1/22/14' AS dt, 5 AS value
UNION
SELECT        '1/23/14' AS dt, 6 AS value
UNION
SELECT        '1/24/14' AS dt, 6 AS value

I created a tablix with dt in the columns value in the data. If I take your average calculation and put it in a row below, it will return 9.8 for every column.

I first used your fill expression to make sure I got the same results as you. Then I altered it to get the correct answer:

=iif(Sum(Fields!value.Value) >  
(Sum(iif(Fields!dt.Value >= Dateadd("d",-10, today()), Fields!value.Value, CDbl(0)), "DataSet1")/10) * 2,
"Gold","White")

With the data I had, none of the cells should turn gold, and that is the result I got. If I change the value for 1/15 to 20 and then preview my table, that cell turns gold because 69/10*2 = 13.8 and 20 > 13.8.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top