need help on Expression syntax

  • Hi all,

    I am trying to create the Expression equivalent of the following query:

    SELECT count(TasksName)

    FROM [db].[dbo].[testdetails]

    where TopLevelProjectName = '40 Project Folder'

    and TasksName = 'Project Info'

    I basically need a working version of this incorrect syntax:

    =CountDistinct(IIF(Fields!TopLevelProjectName.Value = "40 Project Folder" AND Fields!TasksName.Value = "Project Info"))

    Thanks in advance,

    Sharon

  • Just curious, what's wrong with the SQL or better stated, why can't you use it?

  • Sharon S (3/8/2013)


    Hi all,

    I am trying to create the Expression equivalent of the following query:

    SELECT count(TasksName)

    FROM [db].[dbo].[testdetails]

    where TopLevelProjectName = '40 Project Folder'

    and TasksName = 'Project Info'

    I basically need a working version of this incorrect syntax:

    =CountDistinct(IIF(Fields!TopLevelProjectName.Value = "40 Project Folder" AND Fields!TasksName.Value = "Project Info"))

    Thanks in advance,

    Sharon

    The expression you've suggested is different to the query. The SQL will count every non-null occurance of the field "TasksName" that has the fields TopLevelProjectName = '40 Project Folder'

    and TasksName = 'Project Info' on the same row.

    A CountDistinct in an SSRS expression will count distinct instances of a field. Which field are you counting? Counting TasksName distinctly where you've specified it must be equal to "Project Info" is not going to work. For example if you did something like this:

    =CountDistinct(IIF(Fields!TopLevelProjectName.Value = "40 Project Folder" AND Fields!TasksName.Value = "Project Info",Fields!FieldToBeCounted.value,Nothing))

    You would need to specify a third column that might have different distinct info in it that you want to be counting. If you used the TasksName field, then this expression would always return 1 (or possibly 0 if no rows had both of those criteria). I don't think that's what you want here.

    If you use a different FieldToBeCounted, and it has data that repeats then again the CountDistinct might not be what you want. You might just want a Count, and if so you could then use TasksName.

    It helps to explain why you want to do this, because just giving you this answer might actually not help you at all and produce a sub-optimal outcome for you.

  • Sharon S (3/8/2013)


    Hi all,

    I am trying to create the Expression equivalent of the following query:

    SELECT count(TasksName)

    FROM [db].[dbo].[testdetails]

    where TopLevelProjectName = '40 Project Folder'

    and TasksName = 'Project Info'

    I basically need a working version of this incorrect syntax:

    =CountDistinct(IIF(Fields!TopLevelProjectName.Value = "40 Project Folder" AND Fields!TasksName.Value = "Project Info"))

    Thanks in advance,

    Sharon

    You could try something like this (I'm not at a computer with BIDS right now, so I can't be certain my syntax is EXACTLY right 🙂 ):

    =Sum(IIF(Fields!TopLevelProjectName.Value = "40 Project Folder", IIF(Fields!TasksName.Value = "Project Info", 1, 0), 0))

    The nested IIFs test your conditions - if both are TRUE, they return 1; if not, they return 0. The SUM function then adds up all the 1s and 0s, and the total equals the number of rows where TopLevelProjectName = "40 Project Folder" and TasksName = "Project Info".

    Jason Wolfkill

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply