Search code examples
c#crystal-reportsreportrdlc

How to show Double grouped report


Let suppose the result of my SQL query is

Colour   size    week 1  week2  week 3


Black      x       1      2       3

white      xx      1      1       0

yellow     large   2      1       0

I want to generate a report from this query like that.

               week 1               week 2              week 3
    ----------------------------------------------------------------
           x   xx   large       x   xx   large        x   xx   large
   ----------------------       --------------        -------------                                            
    black  1     0    0         2    0    0           3    0     0 

    white  1     0    0         0    1    0           0    0     0

    yellow 2     0    0         0    2    0           0    0     0

The possibilities I have think so for!

  1. In RDLC report change the the report XML at run time.(Very complex as sizes and colors are random)

  2. In Crystal report create a new report for each week and in last show them as subreports in main report.(Is this efficient what will be if I have to create report for 15 weeks or more).

  3. Create cross tab for each week and align them to look like above report.

Will some body suggest me what is best way to generate report in above format. Is some thing I am missing.


Solution

  • This could be accomplished using grouping, but it would take a great deal of effort. Assuming that the weeks columns is static, you would essentially need to group by every data column (weeks, size, color) and then put your headers in the group footers with summaries or running totals carrying your values down to where you need them.

    The first part was intentionally vague because describing this in exact detail would be complicated so I was going to instead propose a different solution. Instead you can use a cross tab, but as your sql is currently constructed I believe it would require a separate cross tab for each week.

    I propose, and it's based on some assumption, but I'm assuming that you have the ability to control the sql query coming into the report. If you could I believe it would be better to reformat the sql query and let the cross tab do all of the work instead of breaking the weeks out yourself. In the first part of my answer I assumed that the weeks were static, but I am guessing that this is not the ultimate solution in which case I think that if you use a data ouput as below you should be able to create a crosstab that will allow you to display your weeks as columns.

    Color    size    week    amt
    
    Black      x       1      1
    Black      x       2      2
    Black      x       3      3
    white      xx      1      1    
    white      xx      2      1
    white      xx      3      0
    yellow     large   1      2
    yellow     large   2      1
    yellow     large   3      0
    

    This is untested so don't shoot me, but I believe with this layout you simply need to make the weeks and size column the fields in the columns section of the cross tab, the color field in the rows section of the cross tab and the amount in the summarized fields section.

    In general I try to answer the question asked on here before I propose a solution and understand that I didn't in this case, but if you have the ability to modify the sql query the report takes in, I believe this is a better solution. Let me know if you have any issues. Hope this helps.