SSRS - How to Sum the Different Group Total

Mohamed Yusuff 0 Reputation points
2023-05-21T16:35:19.52+00:00

I have designed a report to show a Project wise Profit and Loss details as shown in the below screenshot

My challenge is to find an expression that could sum the previous group`s (PNLGroup) total together and show it as the Total at the end of each group

User's image

Group a,b,c,d

Current Expression:- (Yello Highlighted Field)

=SWITCH

(

Fields!Calculated_PNLGroup.Value = "a",iif(IsNothing(Sum(Fields!Calculated_NetAmount.Value)),0,Sum(Fields!Calculated_NetAmount.Value)),

Fields!Calculated_PNLGroup.Value = "b", Previous( iif(IsNothing(Sum(Fields!Calculated_NetAmount.Value)),0,Sum(Fields!Calculated_NetAmount.Value))) + iif(IsNothing(Sum(Fields!Calculated_NetAmount.Value)),0,Sum(Fields!Calculated_NetAmount.Value)),

Fields!Calculated_PNLGroup.Value = "c",Previous( iif(IsNothing(Sum(Fields!Calculated_NetAmount.Value)),0,Sum(Fields!Calculated_NetAmount.Value))) + iif(IsNothing(Sum(Fields!Calculated_NetAmount.Value)),0,Sum(Fields!Calculated_NetAmount.Value)),

Fields!Calculated_PNLGroup.Value = "d", Previous( iif(IsNothing(Sum(Fields!Calculated_NetAmount.Value)),0,Sum(Fields!Calculated_NetAmount.Value))) + iif(IsNothing(Sum(Fields!Calculated_NetAmount.Value)),0,Sum(Fields!Calculated_NetAmount.Value))

)

The Output is shown below (Yellow Highlighted)

User's image

The total of group a & b is correct according to the expression but Group C (Net Profit) total is wrong

The expected output should be (Group B Total + Sum(Groupc))

Group B Total = -41,893,316.92 + (2,341,630 + 1,331,053 + 780,193 + 231,123) = -37,209,317 instead its showing the value as 12,999,855.77

Kindly advise the correct expression to be used

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.
3,063 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Anonymous
    2023-05-22T01:46:46.8666667+00:00

    Hi @Mohamed Yusuff

    Do you want to add up the totals for each group? If your expression meets the requirements, then you can try using the RunningValue function. For example:

    1

    Preview:

    2

    For more details, you can refer to this link: https://learn.microsoft.com/en-us/sql/reporting-services/report-design/report-builder-functions-runningvalue-function?view=sql-server-ver16.

    Best regards,

    Aniya


  2. Anonymous
    2023-05-25T02:32:53.62+00:00

    Hi @Mohamed Yusuff

    Sorry for getting back to you so late. I just noticed that you're using matrices, whereas I'm testing tables. I redesigned a matrix to test it out for you.

    When I changed the scope to the parent group, it did show only the total for each group, not the sum of the totals, as you showed. You can try changing the scope to Nothing. Nothing specifies the outermost context, usually a report dataset.

    Here are my test results.

    3

    4

    Best regards,

    Aniya


Your answer

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