Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6745131
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:10:03+00:00 2026-05-26T12:10:03+00:00

This is a bit hard to explain in words … I’m trying to calculate

  • 0

This is a bit hard to explain in words … I’m trying to calculate a sum of grouped distinct values in a matrix. Let’s say I have the following data returned by a SQL query:

------------------------------------------------
| Group | ParentID | ChildID | ParentProdCount |
|     A |        1 |       1 |               2 |
|     A |        1 |       2 |               2 |
|     A |        1 |       3 |               2 |
|     A |        1 |       4 |               2 |
|     A |        2 |       5 |               3 |
|     A |        2 |       6 |               3 |
|     A |        2 |       7 |               3 |
|     A |        2 |       8 |               3 |
|     B |        3 |       9 |               1 |
|     B |        3 |      10 |               1 |
|     B |        3 |      11 |               1 |
------------------------------------------------

There’s some other data in the query, but it’s irrelevant. ParentProdCount is specific to the ParentID.

Now, I have a matrix in the MS Report Designer in which I’m trying to calculate a sum for ParentProdCount (grouped by “Group”). If I just add the expression

=Sum(Fields!ParentProdCount.Value)

I get a result 20 for Group A and 3 for Group B, which is incorrect. The correct values should be 5 for group A and 1 for group B. This wouldn’t happen if there wasn’t ChildID involved, but I have to use some other child-specific data in the same matrix.

I tried to nest FIRST() and SUM() aggregate functions but apparently it’s not possible to have nested aggregation functions, even when they have scopes defined.

I’m pretty sure there is some way to calculate the grouped distinct sum without needing to create another SQL query. Anyone got an idea how to do that?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T12:10:04+00:00Added an answer on May 26, 2026 at 12:10 pm

    Ok I got this sorted out by adding a ROW_NUMBER() function my SQL query:

    SELECT Group, ParentID, ROW_NUMBER() OVER (PARTITION BY ParentID ORDER BY ChildID ASC) AS Position, ChildID, ParentProdCount FROM Table
    

    and then I replaced the SSRS SUM function with

    =SUM(IIF(Position = 1, ParentProdCount.Value, 0))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a bit hard to explain, so I'll try with an example. Let's
This is something that I always find a bit hard to explain to others:
This is a bit hard to explain, but I seem to be occasionally unable
Okay, this will be a bit hard to explain, but I'll try my best.
It's a bit hard to explain in words, so I'll give an example: (The
This is a bit hard to explain but I'll give it a go. Lets
This is a bit hard to explain. I have a website with a lot
This is a bit hard for me to articulate, but in PHP you can
its a little bit hard to understand. in the header.php i have this code:
This is going to be fairly hard to explain, so I've put together a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.