简体   繁体   中英

SSRS - Expression to calculate percentage based on Tablix data region

I have a SSRS report with the following tablix6:

Account Types
----------------------------------------------
Code   Description              Total   %
-----------------------------------------------
A      Status Code: None        46549   
C      Status Code: Close       12956
L      Status Code: Deceased    477

The dataset that populates this Tablix filters the data by (Section = 4 and DataType = 4). This in effect, when trying to calculate the sum of Total, I get an incorrect value.

I'm trying to get a sum total of 59982.

I need the sum of total of only this tablix filtered data region in order to calculate the percentage on each line item.

Herewith the end result I'm trying to achieve:

Account Types
----------------------------------------------
Code   Description              Total   %
-----------------------------------------------
A      Status Code: None        46549   77%
C      Status Code: Close       12956   21%
L      Status Code: Deceased    477     0.7%

Note: this Tablix is filtering a dataset to display selected items only.

i would use an expression something along the lines of

=sum(Fields!Total.Value) / sum(Fields!Total.Value, "DataSetName") 

assuming the filter is working as a parameter on the dataset

If you can use the query that was used to generate the first table you have in your question then you can use something like the following to get the percentage:

SELECT M.Code, M.Description, M.Total, 
  M.Total / 
  (
    SELECT SUM(S.Total) 
    FROM AcountSummary AS S
  ) * 100 AS PercentageOf
FROM AcountSummary AS M

You can use the OVER function.

SELECT Code, Description, Total, CAST(Total AS FLOAT) / SUM(Total) OVER() [Percentage]
FROM AccountType

Add this to your data source, after this you can format the Textbox to use format P2 for Percentage with 2 decimal places.

Hope this helps

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM