Need equivalent of "count distinct where" in Reporting Services

Posted on 2007-09-28
Last Modified: 2008-06-11
I have a countdistinct query that runs well in enterprise manager but not in reporting services:
select count (distinct VendorNum) from tblMaster where deficiencyID is null  
(returns expected results)

When I convert the query to what RS seems to like:
CountDistinct(Fields!VendorNum.Value) where Fields!DeficiencyId.Value is null
I get a message indicating it is not valid.  If I remove the 'where' clause, it work fine.  But it the results are not as desired.

Any ideas on how to accomplish this in Reporting Services?  We don't do it in the stored procedure that produces the resultset because the user has the opportunity to use grouping or not, and to pick from several grouping values.

Question by:larrysun
    LVL 16

    Accepted Solution

    =IIF(Fields!DeficiencyId.Value is null, CountDistinct(Fields!VendorNum.Value), "NULL")

    Author Comment

    Perfect!  Thanks.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    I recently came across an interesting Question In EE ( and was puzzled about how to achieve that using SSIS out of the box tasks, which was i…
    JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
    Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
    Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now