Friday, July 1, 2011

Running Total at Page Footer

I was Asked by my client to Display the Running Total at the Page Footer ,
Initially thought it was an easy task ...Just Refer the Text Box where the field was Placed and do some small Rework would yield the Result,,But NO !!!! !!!It Turned out to be harder than what i expected.
After some amount of googling,I have Written this Sample Vb Script which will display Running total at the page Footer.

Copy Paste this Vb Code in your Report Code.
Public Shared PageTotal As System.Collections.Generic.Dictionary(Of Integer, Decimal)



Public Shared Function GetTotal(ByVal Item As Integer, ByVal Amount As Decimal) As Decimal

Dim Count As Integer
Dim total As Decimal = 0

If PageTotal Is Nothing Then

PageTotal = New System.Collections.Generic.Dictionary(Of Integer, Decimal)

End If





If Not PageTotal.ContainsKey(Item) Then

PageTotal.Add(Item, Amount)

End If




For Count = 1 To Item
total = total + PageTotal(Count)
Next
Return total



End Function


Use the Expression in your Report Footer..
Code.GetTotal(Globals!PageNumber,Sum(ReportItems!YourMeasure.Value))

Change the Expression and Paste the Measure which you need to display.

Now You Can See the Magic of the Vb Scipt !! ! ! !

Interesting MDX on MSDN Forum

There was an Interesting MDX Query Which i cam through in MSDN Forum Posted by Piasevoli thought its worth Sharing with All.
.

with
member [Product].[Product].[AllProducts] AS [Product].[Product].[All Products]
,BACK_COLOR ="&H0000D00D"

MEMBER [Product].[Product].Remainder
AS Aggregate(
[Product].[Product].[Product].MEMBERS -
EXTRACT(
TOPCOUNT(
[Date].[Fiscal Year].CURRENTMEMBER *
NonEmpty([Product].[Product].[Product].MEMBERS, [Measures].[Internet Sales Amount]),
3,
[Measures].[Internet Sales Amount]
)
,[Product].[Product])
), BACK_COLOR ="&H0000FFFF"

set TopSetWithReminder as
Generate(
[Date].[Fiscal Year].[Fiscal Year].MEMBERS,
UNION(
TOPCOUNT
(
[Date].[Fiscal Year].CURRENTMEMBER *
NonEmpty([Product].[Product].[Product].MEMBERS, [Measures].[Internet Sales Amount]),
3,
[Measures].[Internet Sales Amount]
),
([Date].[Fiscal Year].CURRENTMEMBER,[Product].[Product].Remainder),
([Date].[Fiscal Year].CURRENTMEMBER,[Product].[Product].[AllProducts] )
)
)

SELECT
{
[Measures].[Internet Sales Amount]
,[Measures].[Internet Gross Profit]
} ON 0,
TopSetWithReminder ON 1
FROM
[Adventure Works]
CELL PROPERTIES FORMATTED_VALUE, BACK_COLOR