nested iif statement not working

Systems Administration 1 Reputation point
2021-06-08T13:37:13.373+00:00

Hello,
If I have this table with the values below but for the "chng Date" and "ss State" I just want one row.
I have tried this SSRS iif Statment and it is not giving me one row:
=IIf(Fields!ss_State.Value = "TimeCarded" OR Fields!ss_State.Value = "Approved", Fields!ChngDate.Value,
IIf(Fields!ss_State.Value = "Posted", Fields!ChngDate.Value ,
Fields!ChngDate.Value ) )
Please advise.
ed EE ID Dateworked Chng Date ss State
22833 May 19, 2021 3-5-2021 12:00:00 AM Posted
5-20-2021 12:00:00 AM Timecard
May 20, 2021 3-5-2021 12:00:00 AM Posted
5-20-2021 12:00:00 AM Timecard
May 23, 2021 3-5-2021 12:00:00 AM Posted
6-1-2021 12:00:00 AM Approved
May 24, 2021 3-5-2021 12:00:00 AM Posted
6-1-2021 12:00:00 AM Approved

SQL Server Reporting Services
SQL Server Reporting Services
A SQL Server technology that supports the creation, management, and delivery of both traditional, paper-oriented reports and interactive, web-based reports.
3,061 questions
0 comments No comments
{count} votes

4 answers

Sort by: Most helpful
  1. Michael Taylor 60,161 Reputation points
    2021-06-08T13:52:26.65+00:00

    You're using the same expression Fields!ChngDate.Value for both the true and false cases so this if statement isn't doing anything. Note that if your dataset has 4 rows then the resulting table in SSRS is going to have 4 rows as well. You cannot use expressions to combine rows like that which it seems is what you're wanting to do. If you want to combine rows together then you need to use grouping instead. Grouping will allow you to combine related rows together into a single row. But given that your example if statement is using the same value for all combinations of true and false it is unclear how to group. At a first pass I'd say group by ss_State to get all the rows for a particular state together but I'm just guessing based upon the limited data provided.

    For SSRS also note that you can tell it to put some fields in rows, some in columns and some in the details. Therefore you can use this to "combine" rows as well in some cases. For example you might specify the state as the rows and the dates as the columns leaving the details to show only the fields that are remaining. But it is really dependent upon the data and what you want to show.

    Ultimately you might do better to go back to your dataset in the designer and adjust the query until you get the data you need. In general it is better, and easier, to use SSMS/Azure Data Studio to get a working query and then use that for your dataset rather than blindly loading data from the tables and then using SSRS expressions to manipulate the data. So personally I would recommend you start with fixing your query to return the data organized the way you want.


  2. Systems Administration 1 Reputation point
    2021-06-08T15:17:34.743+00:00

    If I use a switch in the chng date group expression then I get empty cells for chng date. This is the expression I used. Should I remove the detail level?

    103389-ssrs-snip.png


  3. ZoeHui-MSFT 41,491 Reputation points
    2021-06-09T01:51:11.137+00:00

    Hi @Systems Administration ,

    for the "chng Date" and "ss State" I just want one row

    Not really clear about your need.

    Could you please describe it with more details? (screenshot is welcome.)

    It seems the original data is like below, what's the result you want?

    103605-screenshot-2021-06-09-095031.jpg

    Regards,

    Zoe


    If the answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
    Hot issues October


  4. Systems Administration 1 Reputation point
    2021-06-10T11:47:19.807+00:00

    Could we not retrieve my goal by having the chng date in a desc order then have the "first" function row selected for the group of chng dates?

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.