简体   繁体   中英

SSRS REPORT SQL

I have data as below

Year Period Country     STATUS  COST1  COST2  TOTAL COST
2019 1      Australia   PERM    100    200      300
2019 2      NZ          PERM    200    200      400
2019 3      ASIA        TEMP    400    200      600
2019 4      NZ          TEMP    500    200      700

I like to show in the SSRS report I need period on COLUMN and STATUS in ROWS like below and total cost in data section

     Period
     1   2    3   4

+PERM TOTAL COST

+TEMP And when end user toggle on + it will show more detail. But otherwise just like that.

       Year        Country            COST1  COST2  TOTAL COST
 PERM  2019 1      Australia             100    200      300
       2019 2      NZ                    200    200      400
 TEMP 2019 3      ASIA                  400    200      600
       2019 4      NZ                    500    200      700

thanks in advance

You seem to want conditional aggregation:

select status,
       sum(case when period = 1 then total_cost else 0 end) as total_cost_1,
       sum(case when period = 2 then total_cost else 0 end) as total_cost_2,
       sum(case when period = 3 then total_cost else 0 end) as total_cost_3,
       sum(case when period = 4 then total_cost else 0 end) as total_cost_4
from t
group by status;

With a Matrix in SSRS you can set the row groups to be based on the Period and Status without having to add an additional dataset.

Use Period for the Column Grouping so the field will expand to 4 columns based on the Period values. 在此处输入图片说明

Result: 在此处输入图片说明 This way you can have the detail below in the same table and hide it until the user toggles it.

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