Can I create a variable in my report to compare values?

Bob-7209 86 Reputation points
2026-07-16T16:05:29.8066667+00:00

I have an SSRS report that shows student grades. The user can choose to group the results by major, degree, instructor, etc. I need it to filter records if they do not fit the grouping choice. The only issue I am having is when I group by the instructor.

The report currently looks like this. The instructor is shown above the black line. I need to filter out courses under the student that are not this instructor. The 2nd and 3rd students both have a course with Sabrina Locke, so they are shown under the same black line, but I need to remove their courses that are not for Sabrina Locke.

CURRENT

My goal is end up with this result. I highlighted where the values should match. The problem is that the instructor in both areas is being populated by the same field in the dataset.

It seems to me that I need a variable in the instructor cell above the line. I want to compare the courses for each student to that variable and only show the record when the two match.

Is this the best approach? Is this something you can help with?

FUTURE

For more context, the report will look like this if they group by the major. This is already correct. I only need it to change when grouping by the instructor.

MAJOR

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

Answer accepted by question author

AI answer

2026-07-16T16:06:08.9733333+00:00

Yes. A group variable is the right fit for this scenario.

A group variable is calculated once per group instance and can be used in expressions from nested child groups. That matches the requirement when the outer group is Instructor and the child rows are the student’s courses.

A workable approach is:

  1. Define the outer group by Instructor.
  2. Create a group variable on that Instructor group to hold the instructor value shown above the black line.
  3. On the child group or detail rows that list courses, add a group filter that compares the course Instructor field to that group variable.

In Report Builder / SSRS:

  1. Open the report in Design view.
  2. In the tablix, select the Instructor parent group.
  3. Open Group Properties for that group.
  4. Define a group variable for the instructor value.
    • Group variables are intended for expressions scoped to the group and accessed from nested groups.
  5. Then select the child row group or detail group that displays the courses.
  6. Right-click it in the Grouping pane and select Group Properties.
  7. Select Filters.
  8. Add a filter:
    • Expression: the dataset field for the course instructor
    • Operator: =
    • Value: the Instructor group variable
  9. Select OK.

This keeps only the course rows whose instructor matches the current Instructor group instance.

This approach is consistent with how SSRS processes grouped data:

  • Filters can be applied at the data region group level.
  • Group variables are available to nested child groups.
  • Group expressions are evaluated after filters are applied to the data in the report.

If the report must behave differently only when the user selects group by Instructor, apply this filter only on the Instructor-based grouping path. If the same tablix is reused for other grouping choices such as Major, avoid applying the Instructor-match filter there, because it would remove valid rows for those other groupings.


AI-generated content may be incorrect. Read our transparency notes for more information.

Was this answer helpful?

1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

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.