简体   繁体   中英

ssrs nested IIF to compare the two Data sets

I need create a Delta Report which is based on the two data sets ie DataSet1 and DataSet2. I need take DataSet2 as reference if there is any change in any field value in DataSet1 I need change the color of the text box. can anybody help me in this I wrote some code but its throwing Error.

=IIF(Fields!CIF.value, "DataSet1" = Fields!CIF.value, "DataSet2" AND Fields!Account_ID.value,"DataSet1" = Fields!Account_ID.value,"DataSet2", 
                        IIF( Fields!Account_balance.value, "DataSet1" <> Fields!Account_balance.value, "DataSet2","Yellow","Transparent"),"Transparent","Transparent")

You can't mix datasets.

This will only work if your datasets each only have one row of data. Otherwise you'll need to figure out how to isolate the value you need.

=IIF(MAX(Fields!CIF.value, "DataSet1") = MAX(Fields!CIF.value, "DataSet2") AND MAX(Fields!Account_ID.value, "DataSet1") = MAX(Fields!Account_ID.value, "DataSet2"), 
    IIF(MAX(Fields!Account_balance.value, "DataSet1") <> MAX(Fields!Account_balance.value, "DataSet2"), "Yellow", "Transparent"), "Transparent")

Usually you'd have one dataset in a table and then look up the corresponding value in the other dataset.

If your CIF and Account ID are the common identifiers and you want to compate the Account Balances of each, I would base the table on dataset 1 and then bring in the value from dataset2 to compare. Combine the CIF and Account ID into a single text string for comparison.

Your color expression would then be something like:

=Lookup(Fields!CIF.value & "|" & Fields!Account_ID.value, Fields!CIF.value & "|" & Fields!Account_ID.value, Account_balance.value, "DataSet2")

SSRS:

Use Lookup to retrieve the value from the specified dataset for a name-value pair where there is a 1-to-1 relationship. For example, for an ID field in a table, you can use Lookup to retrieve the corresponding Name field from a dataset that is not bound to the data region.

Another approach would be to do this in a stored procedure and return the results as one dataset. For example, assume I have 10 fields in the tables. I can create a hash of the data for each record:

select
    CASE WHEN chkHash2 = chkHash1 THEN 0 ELSE 1 END as 'ChgFlag'
    ,a.*
FROM
(
    select
        HASHBYTES('md5', t2.Field1 + t2.Field2 + ... + t2.Field10) as 'chkHash2'
        ,HASHBYTES('md5', t1.Field1 + t1.Field2 + ... + t1.Field10) as 'chkHash1'
        ,t1.Field1, t1.Field2, ... t1.Field10
    From Table2 t2
    LEFT JOIN Table1 t1 on t1.ID = t2.ID
) a

Big Assumption ... both tables have an ID that is unique and related. This will give you a result set of Table1 (dataset1) fields and a flag that will tell you when any field has changed from Table2 (dataset2).

Depending on your application, this could be easier and faster. I always try to do the WORK in SQL as opposed to SSRS.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM