Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Analysis Server and Reporting Services (2008)
 Switch Formula Add up depend on Month for Report

Author  Topic 

micnie_2020
Posting Yak Master

232 Posts

Posted - 2014-03-30 : 12:57:21
Hi All,

I have this:-

=Switch(Fields!Months.Value="Apr",Fields!amount.Value,Fields!Months.Value="May",Fields!amount.Value,Fields!Months.Value="Jun",Fields!amount.Value,Fields!Months.Value="Jul",Fields!amount.Value,Fields!Months.Value="Aug",Fields!amount.Value,Fields!Months.Value="Sep",Fields!amount.Value,Fields!Months.Value="Oct",Fields!amount.Value,Fields!Months.Value="Nov",Fields!amount.Value,Fields!Months.Value="Dec",Fields!amount.Value,Fields!Months.Value="Jan",Fields!amount.Value,Fields!Months.Value="Feb",Fields!amount.Value,Fields!Months.Value="Mar",Fields!amount.Value)

I try modify to:
=Switch(Fields!Months.Value="Apr",Fields!amount.Value,Fields!Months.Value="May",Fields!amount.Value+IIF(Fields!Months.Value="Apr",Fields!amount.Value,0)....

Eg: But it's not add up apr & may for May amount


The output required as
1) if Fields!Months.Value="May" supposed to add up amount for month Apr & May
2) if Fields!Months.Value="Jun" supposed to add up amount for month Apr & May & Jun
3) if Fields!Months.Value="Jul" supposed to add up amount for month Apr & May & Jun & Jul
:
:
Please advise.

Thank you.

Regards,
Micheale

sqlsaga
Yak Posting Veteran

93 Posts

Posted - 2014-03-31 : 12:00:52
Looks like you are creating this formula in SSRS, What is your source? SQL Database or SSAS cube? If it's a SQL Query, you can always use a running total concept and build up the sum from the next immediate month and display that in the report. For SSAS, you can write an MDX script and make it happen.

For an article about Running totals for a SQL Database, look at this link.. http://sqlsaga.com/sql-server/how-to-calculate-running-totals-in-sql-server/



Visit www.sqlsaga.com for more t-sql code snippets and BI related how to articles.
Go to Top of Page
   

- Advertisement -