Hitachi Vantara Pentaho Community Forums
Results 1 to 20 of 20

Thread: Hide a Subreport if No Data

  1. #1

    Default Hide a Subreport if No Data

    I have a report with several subreports. Depending on the parameter values passed to the report, some subreports may return no data. Is it possible to completely hide a subreport if there is no data?

    As it is now, if there is no data, then I get a chart shell that says No Data, whatever I have in the no data section, and lines (if I have them in the subreport). I'd like to display nothing at all...

    Thanks,

    Chris

  2. #2

    Default

    Have you tried the "ShowElementIfDataAvailable" function? This should allow you to hide the sub-report (though I haven't tried it on sub-report elements).
    BizCubed Pty Ltd
    Australian Pentaho Partner

  3. #3
    Join Date
    Mar 2003
    Posts
    8,085

    Default

    Well, the ShowElementIfDataAvailable and its brother HideElementIfDataAvailable are deprecated now.

    You can achieve the same using a plain formula on the visible style-key:

    Code:
    =Not(IsEmptyData())
    Which make the element or band invisible if the query returned zero rows.
    Get the latest news and tips and tricks for Pentaho Reporting at the Pentaho Reporting Blog.

  4. #4

    Default RE: Hide a Subreport if No Data

    I tried using visible:=Not(IsEmptyData()) in the style expression for the subreport header, unfortunately it doesn't seem to work. Maybe this isn't working with subreports yet?

  5. #5

    Default

    Hi Chris,

    I would place the sub report in a sub-band and use style expression in the sub-band and see if that works...
    BizCubed Pty Ltd
    Australian Pentaho Partner

  6. #6
    Join Date
    Dec 2008
    Posts
    1

    Default

    =Not(IsEmptyData()) seems to generate "LibFormulaErrorValue{errorCode=505}

  7. #7
    Join Date
    Jun 2007
    Posts
    112

    Default

    I made this work by creating a TotalItemCount function called TotalCount and then setting my visible style expression to =NOT([TotalCount]=0)

  8. #8
    Join Date
    Apr 2007
    Posts
    2,010

    Default

    I get that libformula error too I'll go for the total item count option!

  9. #9
    Join Date
    Jul 2008
    Posts
    23

    Default

    Quote Originally Posted by Nathan View Post
    I made this work by creating a TotalItemCount function called TotalCount and then setting my visible style expression to =NOT([TotalCount]=0)
    Hi Nathan,
    Where did you set that property to hide the subreport?

    It is not possbible to set it on a subband as it cant contain a subreport...

  10. #10
    Join Date
    Apr 2007
    Posts
    2,010

    Default

    b.t.w. isEmptyData() isnt doco'd on the wiki!

  11. #11
    Join Date
    Mar 2003
    Posts
    8,085

    Default

    Not all formula-functions are documented on the wiki (yet).

    However, the formula-function appears in the formula-editor (in the Information-category). The function was added *after* 0.8.9, so the old report-designer does not have that function.

    And remember: there are two ways to hide a subreport: The visible style uses the context of the parent report to evaluate the report's visibility. So the calculation uses the parent's data and the parent's other functions. If invisible, the subreports query is not fired.

    The attribute "subreport-active" (in the common group) uses the subreport's internal state to evaluate whether the report should run. So it uses the subreport's data and the subreport's functions for that task. The subreport's query will be executed during the process.
    Get the latest news and tips and tricks for Pentaho Reporting at the Pentaho Reporting Blog.

  12. #12

    Default

    Hi there,

    I'm trying to do exactly what you say.

    I have several subreports and I want them not to appear if the results of their queries are 0. There are several consecutive ones.

    1) My first option was to set the visible option of all the elements of a single sub-report with my formula:
    =NOT([agvis]=0)
    agvis is the result of a mysql query, which basically does not give NULL never, it can only throw a number or 0.

    It worked but then I got a 14points blank space there, i think due to the 14 points-height of this subreport.

    2) Then I read this post, and I set (after undoing above edits) sub-report active option with my formula. But it does not work, subreport is hidden, but even having the 'invisible-consumes-space' option disabled, as it is by default, i got that undesired blank space.

    I don't really know if my goal can be achieved. I was playing with 'preferred-height', 'max-height' but I don't get what I want, that is basically to force the sub-report not to exist if its internal query gives '0'.

    Any hint?

    Thanx in advance
    Last edited by hberges; 01-30-2010 at 08:32 PM.

  13. #13

    Default invisible-consumes-height is partying, phone back later

    After having tried several workarounds i found out that it's barely impossible to hide any banded (full wide) element, sub-report (even the inline one manually expanded) or even rectangle, I mean, hiding is fine, but I cannot delete that blank space that the invisible element leaves in order to next element to fit that empty space.
    I tried combining some of the properties, like the invisible-consumes-space(see title), setting conditionally the sub-report height to 0... etc but no success.

  14. #14
    Join Date
    Jun 2009
    Posts
    1

    Default

    I found a surprising solution to this problem. I set the height of the subreport to always be zero. When the subreport returns data the data gets displayed. When it doesn't return data the subreport disappears AND doesn't take up any blank space.

  15. #15
    Join Date
    Feb 2013
    Posts
    4

    Thumbs up

    Quote Originally Posted by brilav View Post
    I found a surprising solution to this problem. I set the height of the subreport to always be zero. When the subreport returns data the data gets displayed. When it doesn't return data the subreport disappears AND doesn't take up any blank space.


    I tried it and it works fine ... Thank you very much ..

  16. #16
    Join Date
    Feb 2013
    Posts
    4

    Default

    Quote Originally Posted by brilav View Post
    I found a surprising solution to this problem. I set the height of the subreport to always be zero. When the subreport returns data the data gets displayed. When it doesn't return data the subreport disappears AND doesn't take up any blank space.
    It is working Brilav ... Thank you very much

  17. #17
    Join Date
    Oct 2006
    Posts
    219

    Default

    Quote Originally Posted by brilav View Post
    I found a surprising solution to this problem. I set the height of the subreport to always be zero. When the subreport returns data the data gets displayed. When it doesn't return data the subreport disappears AND doesn't take up any blank space.
    This is fine if your sub report doesn't contain data but what if it contains other items like images that will ALWAYS be displayed / consume space when added. You could *maybe* attach a formula to these sub report images / charts / other items to NOT render if there is no data but once again you will get the item consuming that space that was required in the first place. Setting the height of text to 0 is fine but not for images / charts.

    This is still an issue
    www.ivy-is.co.uk - Ivy Information Systems

    Come join the non official Pentaho IRC chat room on irc.freenode.net in the ##pentaho channel

  18. #18
    Join Date
    Mar 2003
    Posts
    8,085

    Default

    Revisiting an ancient thread does not do anyone any good.

    Subreports have a extra attribute (subreport-active) that allows them to be hidden if the subreport's query does not contain data (or does not match any other criteria expressed in the formula of that attribute). This has been in since maybe 2011 or so - so long that I cant even remember when exactly we added it.
    Get the latest news and tips and tricks for Pentaho Reporting at the Pentaho Reporting Blog.

  19. #19

    Default

    Quote Originally Posted by Taqua View Post
    Revisiting an ancient thread does not do anyone any good.

    Subreports have a extra attribute (subreport-active) that allows them to be hidden if the subreport's query does not contain data (or does not match any other criteria expressed in the formula of that attribute). This has been in since maybe 2011 or so - so long that I cant even remember when exactly we added it.
    Sow how do you specify this subreport-active? It contains exactly what i need but i cant get it working.

    My subreport has a header which has the layout row, containing 3 labels.
    My details which also has the layoutrow containing 3 numberfields and
    my footer which only has a horizontal line.

    How can i manage to hide the subreport completly when the 3 numberfields in details dont contain any data??

  20. #20
    Join Date
    Nov 2016
    Posts
    1

    Default

    I managed to get this working by using =IF(ISEMPTYDATA();"false";"true"). The report runs correctly and the subreport is not formatted on the report when there are no records. The problem is that now my subreport elements are not visible in the workspace. If I want to view the elements in the subreport, I have to edit the formula in the sub-report-active attribute with a syntax error. Once the formula has a syntax error, the sub-report element displays in the canvas. I am using PRD 6.1.1

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Privacy Policy | Legal Notices | Safe Harbor Privacy Policy

Copyright © 2005 - 2019 Hitachi Vantara Corporation. All Rights Reserved.