Populating with '0' when Data in SSRS Does not exist

后端 未结 2 2027
没有蜡笔的小新
没有蜡笔的小新 2021-01-07 12:02

I\'m trying to create a report in SSRS where I have a matrix, which has gender as the column headings and specifically defined agegroups as the rows. The report is sorted by

2条回答
  •  囚心锁ツ
    2021-01-07 12:46

    I can think of a few ways to do this:

    DataSet level

    Instead of just returning the relevant data in the underlying data in the DataSet, include all the categories you want to display in all cases.

    e.g. For a database query it might be the difference between an inner and left join, i.e. going from something like:

    select *
    from AgeGroup
      inner join MyData on ...
    

    to:

    select *
    from AgeGroup
      left join MyData on ...
    

    So the report always has all the age groups to display. Where there are NULL values, just display 0.

    I think this is the best option if you have control over the DataSet - you won't have to update your report at all, with luck the actual DataSet changes should be minimal, there is still only one DataSet call, and it's by far the simplest to maintain.

    Hard code groups into the report

    Here you include a table header row for each group you want to display, so these are always displayed in all cases.

    Here you have some sort of conditional expression to display the values, e.g. For each group row it will be tailored to that group:

    =Sum(IIf(Fields!AgeGroup.Value = "5-16", Fields!Amount.Value, Nothing)
    

    This is not too flexible and will need updates as you change groups, and doesn't have as many options for layout. There is still only one DataSet call, so that is a plus.

    Subreports

    You can have a parent DataSet that displays one row for each age group, then embed a subreport in each row that displays the data you want for that row.

    This allows you flexibility in layout but it will add complexity to the report(s) and will mean that you make a lot of DataSet calls that could be avoided with other options.

提交回复
热议问题