Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SSRS not showing all rows by level (hierarchy)

Ok folks, this is driving me crazy...

I have a report that pulls back details for a number of features. THese features can hang off others, exist in their own right or both.

I have the following data as the result of the query:

Feature_ID   Parent_ID
24            
24          25
20            
26          12
12            
21          23
26          20
22            
24          23
23          26
24          27
27          28
24          22
29          20
23            
25            
27          29
22          26
28          12

As you can see, some of the features fit in multiple places in the hierarchy. However, all I get back in the report is:

SSRS output

I am grouping on Feature_ID, recursive parent is Parent_ID. What am I missing?

like image 824
JohnHC Avatar asked Sep 30 '16 15:09

JohnHC


People also ask

What are row grouping and column grouping in SSRS?

Row groups and column groups You can organize data into groups by rows or columns. Row groups expand vertically on a page. Column groups expand horizontally on a page. Groups can be nested, for example, group first by [Year], then by [Quarter], then by [Month].

What is difference between table and matrix in SSRS?

Tables and matrices have a tabular layout and their data comes from a single dataset, built on a single data source. The key difference between tables and matrices is that tables can include only row groups, whereas matrices have row groups and column groups.

Where is the tablix properties in SSRS?

The Advanced Tablix Member Properties are located in the Advanced Mode of the Grouping pane (the down arrow turns Advanced on and off).

How do I repeat headers in SSRS report?

Right-click the row, column, or corner handle of a tablix data region, and then click Tablix Properties. In Row Headers, select Repeat header rows on each page. Select OK.


1 Answers

By your wording and unexpected output it feels like you are looking for a list of distinct levels and features. Hopefully the following is helpful. If not, perhaps you can provide some additional context to understand what you are looking for.

declare @table table (Feature_ID int, Parent_ID int);

insert @table values
(24,null),
(24,25),
(20,null),
(26,12),
(12,null),
(21,23),
(26,20),
(22,null),
(24,23),
(23,26),
(24,27),
(27,28),
(24,22),
(29,20),
(23,null),
(25,null),
(27,29),
(22,26),
(28,12);

select * from @table order by 1,2;
select * from @table order by 2,1;

with cte as (
        select  Feature_ID, Parent_ID, 0 [Level], CAST(Feature_ID as varchar(200)) [Path]
        from    @table
        where   Parent_ID is null

        union   all

        select  t.Feature_ID, t.Parent_ID, c.[Level] + 1, cast(c.[Path] + '|' + CAST(t.Feature_ID as varchar(200)) as varchar(200))
        from    @table t
        join    cte c
                on c.Feature_ID = t.Parent_ID
)
select  distinct [Level], Feature_ID
from    cte
order   by [Level], Feature_ID;

This gives the following result:

Level   Feature_ID
0   12
0   20
0   22
0   23
0   24
0   25
1   21
1   24
1   26
1   28
1   29
2   22
2   23
2   27
3   21
3   24
like image 110
SMM Avatar answered Nov 05 '22 17:11

SMM