Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

need help on Expression syntax Expand / Collapse
Author
Message
Posted Friday, March 8, 2013 10:18 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Tuesday, January 14, 2014 8:46 AM
Points: 15, Visits: 162
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
Post #1428850
Posted Monday, March 11, 2013 9:52 PM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Yesterday @ 12:01 PM
Points: 134, Visits: 337
Just curious, what's wrong with the SQL or better stated, why can't you use it?
Post #1429569
Posted Wednesday, March 13, 2013 12:08 AM


SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Saturday, September 27, 2014 5:20 AM
Points: 467, Visits: 868
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.
Post #1430229
Posted Wednesday, March 13, 2013 8:34 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Today @ 9:06 AM
Points: 1,061, Visits: 2,565
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
Blog: SQLSouth
Twitter: @SQLSouth
Post #1430434
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse