Issue regarding aggregation function application on column

Stimulsoft Reports.JS discussion
Post Reply
VladU
Posts: 5
Joined: Wed May 20, 2020 12:21 pm

Issue regarding aggregation function application on column

Post by VladU »

Hello,

I have the following data source CSV format:
Stat1,Stat2
raw,raw
:stat1Path,:stat2Path
10,5
20,10
30,15
40,20
50,25

I'm trying to add a 2x3 table:
\ | Stat1 | Stat2 |
Max | - | - |
Avg | - | - |

If I try to write in the table field the expression I want for max/average on a particular column, it doesn't work ( {Max(testing.Stat2)} ). However, if I define a data transformation in which I compute the max/average (using basically the same formula), I can correctly display the value.

Can you please let me know if there is a method I can do this directly without defining for each column a data transformation? I am suspecting the expression I am using is not correct, but I have not found in the documentation a section that explains this part.

I have attached the .mrt file I am using.

Thank you,
Vlad
Attachments
Testing.mrt
(24.82 KiB) Downloaded 95 times
Lech Kulikowski
Posts: 6247
Joined: Tue Mar 20, 2018 5:34 am

Re: Issue regarding aggregation function application on column

Post by Lech Kulikowski »

Hello,

You can use Totals.Max() and Totals.Avg() functions.

Thank you.
Attachments
Testingmodified.mrt
(15.65 KiB) Downloaded 104 times
VladU
Posts: 5
Joined: Wed May 20, 2020 12:21 pm

Re: Issue regarding aggregation function application on column

Post by VladU »

Hello Lech,

Thank you very much for the answer. The Totals.Sum part works perfectly for what I need. However, I'm still having trouble with Totals.Avg as it displays "NaN" which I assume is caused by the fact what the columns also contains non-numeric values.

Would you be kind to also help me with a method to compute the average for just the numeric values. I see that there is a function AvgIf, but I've tried multiple conditions and unfortunately none of them has worked.

Best regards,
Vlad
Lech Kulikowski
Posts: 6247
Joined: Tue Mar 20, 2018 5:34 am

Re: Issue regarding aggregation function application on column

Post by Lech Kulikowski »

Hello,

Your column contains as string and numeric values. Please check the following expression:
{Totals.Avg(testing, (TryParseDecimal(testing.Stat1) == false ? 0 : testing.Stat1 ))}

Thank you.
VladU
Posts: 5
Joined: Wed May 20, 2020 12:21 pm

Re: Issue regarding aggregation function application on column

Post by VladU »

Hello Lech,

This has solved my problem! Thank you very much.

Vlad
Lech Kulikowski
Posts: 6247
Joined: Tue Mar 20, 2018 5:34 am

Re: Issue regarding aggregation function application on column

Post by Lech Kulikowski »

Hello

We are always glad to help you!
Please let us know if you need any additional help.

Thank you.
Post Reply