SSRS Switch function showing error for simple math

summoningknoweldge 1 Reputation point
2022-05-20T13:42:20.637+00:00

This is my data . I have to calculate the value of Banana by subtracting 1-2-3. I want to do it in the report because I feel it will be easier in the report.
204127-image.png

I have a basic report with no groupings.

204158-image.png

For the totals, I do the following calculation:
= SWITCH(
Fields!Order.Value = 6,

   Sum(IIF( Fields!Order.Value = 1 ,CDBL(Fields!Totals.Value),CDBL(0)))  
			- Sum(IIF( Fields!Ordering.Value = 2 ,CDBL(Fields!Totals.Value),CDBL(0)))  
			- Sum(IIF( Fields!Ordering.Value = 3 ,CDBL(Fields!Totals.Value),CDBL(0)))  
			,  
	1 = 1,Sum(Fields!Totals.Value)  
	)  

The issue now is that when I use the expression above, it shows #error for Banana rather than the answer. How can I display the numbers properly?

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,061 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Joyzhao-MSFT 15,631 Reputation points
    2022-05-23T02:10:46.563+00:00

    Hi @summoningknoweldge ,

    Please try the following expression:

    =SUM(Switch(Fields!Order.Value=1,Fields!Total.Value)-Switch(Fields!Order.Value=2,Fields!Total.Value)-Switch(Fields!Order.Value=3,Fields!Total.Value))  
    

    Design:

    204475-01.jpg

    Preview:

    204482-02.jpg

    Best Regards,
    Joy


    If the answer is the right solution, please click "Accept Answer" and kindly 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 Answers by the question author, which helps users to know the answer solved the author's problem.