SSRS - Apply Filter to Aggregate Functions

Anonymous
2022-04-21T19:27:18.907+00:00

Is there a way in an SSRS report itself, not the database, to filter dataset rows queried in an aggregate function.

For example:

Say I have a simple table:

ID ValueA ValueB
1 A 50
2 B 25
3 B 45
4 C 10
5 C 30

I want the FIRST() or even MIN() of ValueB from the above, but where ValueA = B.
I could use either approach as I'm looking for 25.

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.
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Isabellaz-1451 3,616 Reputation points
    2022-04-25T02:33:43.333+00:00

    Hi @Anonymous

    Then you can create 2 parameters ,one for choosing a ValueA, one for calculating the MIN() of ValueB.
    Below is my test steps,hope will help you.
    Create dataset2 to get all the distinct ValueA

    195849-image.png
    Then create the parameter ValueA
    195895-image.png

    195953-image.png
    Then create dataset3 to calculate the MIN() of ValueB
    195914-image.png

    Then create parameter minValueB
    195839-image.png
    195964-image.png

    Then mark the textbox by change the backgroud color
    195903-image.png

    Preview Result
    195915-image.png

    Best Regards,
    Isabella


    If the answer is the right solution, please click "Accept Answer" and upvote it. If you have extra questions about this answer, please click "Comment".
    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.

    1 person found this answer helpful.

  2. Isabellaz-1451 3,616 Reputation points
    2022-04-22T01:29:23.887+00:00

    Hi @Anonymous
    You can get the First() of ValueB by using expression :=First(Fields!ValueB.Value, "DataSet1")

    195344-image.png
    About the MIN() of ValueB,you can add a filter on the dataset,then use expression:=Min(Fields!ValueB.Value, "DataSet1")

    195318-image.png
    195371-image.png
    195362-image.png
    Best Regards,
    Isabella


    If the answer is the right solution, please click "Accept Answer" and upvote it. If you have extra questions about this answer, please click "Comment".
    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.


Your answer

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