Using controls in a footer as expressions in other controls

32 views
Skip to first unread message

Chip Andrews

unread,
Dec 21, 2022, 10:22:08 PM12/21/22
to reportman
I've run into a reporting challenge and I was hoping to get your help.  I have a billing report that is applying discounts based on order quantities being made.  The complexity is that the customer wants the text "Discount was applied to at least one item on the report" to appear in the Customer footer.  In order to implement this, I created an expression called TRpExpression23 where I am computing the MAX aggregate value of all the discount multipliers on each line item.  The logic is simple:  

if TRpExpression23 is null, do not show the text
if TRpExpression23 is not null, show the "discount" text

*Note that a null is shown in the multiplier field when no discount is applied
*If even one line of the report has a discount applied, I should get a non-null value for TRpExpression23

I created a Label field and attempted to have it evaluate TRpExpression23 as a Print Condition.  However, the TRpLabel16 field I created does not recognize TRpExpression23 as a field I can evaluate.  What am I doing wrong? 

Toni Martir

unread,
Dec 22, 2022, 6:27:52 AM12/22/22
to Chip Andrews, reportman
Hello,

There are multiple ways to solve this problem.
I will explain two ways that will allow you to solve this problem but also other problems when designing the report.

I assume your table has a boolean field ISDISCOUNT that is true if the line has a discount, but you can replace YOURTABLE.ISDISCOUNT with any boolean expression to check the discount.

One way to solve the problem is the following:
1.Create a parameter called HASDISCOUNT, integer width value 0. Invisible to user.
2.In after print operation of the amount, or the quantity, or whatever is always printed (for each line) place the expression: 
M.HASDISCOUNT:=MAX(M.HASDISCOUNT, IIF(YOURTABLE.ISDISCOUNT,1,0))
  This will assign 1 to HASDISCOUNT if already is 1 or 1 if the line has a discount.
3.Place the printcondition: M.HASDICOUNT=1 in the lavel

This way is more debuggable as you can print an expression M.HASDISCOUNT, in the detail to see the evolution of the variable over multiple lines and the same at the header and footer to debug the process.

Note: If multiple "invoices" are printed in one report you should place the expression M.HASDISCOUNT:=0 after printing the final footer or at the first header of the invoice to reset the variable.

Other different way is to use expression identifiers, this is also useful to operate with calculated aggregated expressions, and I think the is the way you are looking for:

1.Place an expression at the footer.
Expression:  IIF(YOURTABLE.ISDISCOUNT,1,0))
Aggregate: Group
AggregateGroup: YOURGROUP
AggregateType: MAX

2.Check the expressions prints 1 in invoices with discount and a 0 in others.
3. Set the identifier property to something like: INVOICE_HAS_DISCOUNT.
4. Place a label, with your text and in the print condition set the expression: M.INVOICE_HAS_DICOUNT=1
5. Once it works you can make the expression at step 1 invisible using a print condition of false.

To access aggregated values from expressions you must place an identifier, that variable will contain the aggregated value at each moment in the report calculation.

Thanks


--
You received this message because you are subscribed to the Google Groups "reportman" group.
To unsubscribe from this group and stop receiving emails from it, send an email to reportman+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/reportman/bf43156f-a14f-4597-bbd1-4ece51edd245n%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Toni Martir

Chip Andrews

unread,
Dec 22, 2022, 11:36:56 AM12/22/22
to Toni Martir, reportman
Thank you Toni!  That did the trick.  I took the second suggestion and it worked like a charm.  I made one modification in that instead of an expression and a label, I just used the expression with the IIF statement to actually show the text I wanted if True and nothing if false.  The MAX aggregate then evaluated to my desired output.

I may go back and try the first if I need to do some debugging later.

I also sent you 1hr of support via Paypal.  Hopefully you received that.  
Reply all
Reply to author
Forward
0 new messages