Search code examples
reporting-servicesssrs-2008-r2ssrs-tablix

different dataset in switch in ssrs


I have 2 datasets in a single report, out of the 5 columns 2 are derived from dataset1 and 3 from dataset2 (dataset 2 being the primary dataset). Now when I try to use the below switch command,it does not give me any error but doesn't show any results. The dataset1 is a share point list.

=SWITCH(First(Fields!xyz.Value, "dataset1")="Platinum",25,First(Fields!xyz.Value, "dataset1")="",0,First(Fields!xyz.Value, "dataset1")="Gold",15)

All the other columns in the tablix are from dataset2 and the report runs fine just no data comes in this column


Solution

  • The First() expression is probably the problem, and the reason it's working when you change the IIF condition. First() just literally fetches the first value in the named field from the target dataset, so if it's not "Platinum", an empty string or "Gold" it will just return nothing. On the otherhand, if the first value of abc is 1 or 3 it will always return "Platinum" or "Gold"

    It's important to realise this will return exactly the same data on every single row of the table, since you're only ever looking at the FIRST row of dataset1.

    I think you're probably after the LookUp() function, which will use primary keys to match the datasets and fetch different data from dataset1 depending on the data in the current row of dataset2.

    Hope that sort of makes sense?

    EDIT IN REPLY TO COMMENT:

    You can do this in two ways then. You can either use the same LookUp() formula that you use to populate the column in your switch statement to get the points, for example;

    =Switch(LookUp(Fields!application_name.Value, Fields!application_name.Value, Fields!service_level.Value, "dataset1") = "Platinum", 25, LookUp(Fields!application_name.Value, Fields!application_name.Value, Fields!service_level.Value, "dataset1") = "Gold", 15)
    

    Secondly, you can refer directly to the column that is already fetching "Gold" or "Platinum". For example if that textbox is called Textbox10 (check the top right of the properties panel to see the name) then you can use:

    =Switch(ReportItems!Textbox10.Value = "Platinum", 25, ReportItems!Textbox10.Value = "Gold", 15)
    

    Either method should work fine. Basically what you're doing there is ensuring you always check the right service level for that application rather than just the first one in dataset1