Welcome, Guest. Please login or register.
Did you miss your activation email?

Author Topic: SUM() problem?  (Read 9112 times)

talaadun

  • Newbie
  • *
  • Posts: 11
    • View Profile
SUM() problem?
« on: September 05, 2016, 08:18:19 am »
Hi, I am doing a table test using 1.3.11.

in the right bottom cell, I use script like this:

$S{SUM($D{mydts.column1},"DataBand1")}+$S{SUM($D{mydts.column2},"DataBand1")}

it should display 56+72, but actually it is 56+56, why?




[вложение удалено администратором]

talaadun

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: SUM() problem?
« Reply #1 on: September 05, 2016, 08:21:57 am »
and here is part of the template:



[вложение удалено администратором]

Subst

  • Sr. Member
  • ****
  • Posts: 451
    • View Profile
Re: SUM() problem?
« Reply #2 on: September 05, 2016, 08:47:26 am »
Maybe better way is to use new datasource

add new datasource in DataBrowser, then arrange your connection in Connection combo, named new datasource and
assign SQL query like rhis

select (sum(mydts.column1)+sum(mydts.column2)) as needed_sum from mydts where... (if you want to use condition)

and then use $D{new_datasource.needed_sum}

Also you can use master-detail scheme

talaadun

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: SUM() problem?
« Reply #3 on: September 05, 2016, 09:00:23 am »
Thank you very much, Subst.

Unfortunately my table data is from a data struct in memory, not queried from a real database. And i am using SIGNAL SLOT
mechanism for external data sources according to the user manual.

master-detail scheme can solve this problem? I am not familar with it, let me try it.

Thanks!

Subst

  • Sr. Member
  • ****
  • Posts: 451
    • View Profile
Re: SUM() problem?
« Reply #4 on: September 05, 2016, 09:46:37 am »
Well, in such case easy way next:

create to variables sum1 & sum2

then in Total Column1 write code

$S{
 var sum=SUM($D{mydts.column1},"DataBand1");
 setVariable("sum1",sum);
 sum;
 }

similarly in Total Column2

$S{
 var sum=SUM($D{mydts.column2},"DataBand1");
 setVariable("sum2",sum);
 sum;
 }

And finally in Total Total

$S {
 $V{sum1}+$V{sum2};
 }


talaadun

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: SUM() problem?
« Reply #5 on: September 05, 2016, 10:34:26 am »
Hi Subst,

I used your script, but there is an error: ReferenceError: Can't find variable: setVariable

Subst

  • Sr. Member
  • ****
  • Posts: 451
    • View Profile
Re: SUM() problem?
« Reply #6 on: September 05, 2016, 10:43:53 am »
You need to create two variables in Data Browser -> Variables and call them sum1 and sum2

did you do it?

talaadun

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: SUM() problem?
« Reply #7 on: September 05, 2016, 10:53:25 am »
Hi Subst,

Yes, I added variables: Column1Total, Column2Total, but it just display the error message.




[вложение удалено администратором]

Subst

  • Sr. Member
  • ****
  • Posts: 451
    • View Profile
Re: SUM() problem?
« Reply #8 on: September 05, 2016, 11:08:09 am »
May be your version of LM id too old.
Look at the "Functions" tab (on th right when duble click on the textitem)

Can you see there GENERAL section function setVariable ?

talaadun

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: SUM() problem?
« Reply #9 on: September 05, 2016, 11:17:25 am »
There is no GENERAL section, so I need a new version of LM?

I am using the designer in LR_1_3_11_binares_Qt5.5_VC2010_win32, and limereport_1_3_11.

talaadun

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: SUM() problem?
« Reply #10 on: September 05, 2016, 11:22:06 am »
1.3.11 seems to be the newest version of LM.

I am using VS2008 + Qt4.8.5, but i don't this this is the problem.

Subst

  • Sr. Member
  • ****
  • Posts: 451
    • View Profile
Re: SUM() problem?
« Reply #11 on: September 05, 2016, 11:31:41 am »
Yes. The binaries are old. The 1.3.11 version is newest in binaries but sources on github are greatly modern.

You can build LM from sources yourself .

or I try to solve your problem another way

As apparent variant - solve the needed value in your program and pass them to the report throw setReportVariable like this

m_report->dataManager()->setReportVariable("variable_name",variable_value);
"variable_name" variable must be exists in report, obviously

Subst

  • Sr. Member
  • ****
  • Posts: 451
    • View Profile
Re: SUM() problem?
« Reply #12 on: September 05, 2016, 12:01:44 pm »
Well.
And why u can't calculate sum of "total" field?

talaadun

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: SUM() problem?
« Reply #13 on: September 05, 2016, 12:12:57 pm »
Hi Subst,

I just downloaded the source code from github and built the entire solution. Now it works fine.

>> And why u can't calculate sum of "total" field?
Actually there is no "total" field in my data struct, this column is calculated by column1 and column2:
$S{$D{mydts.column1}+$D{mydts.column2}}
it seems that i cannot calculate the sum by "total" column.

Thank you so much for helping me solve this problem! :)

Subst

  • Sr. Member
  • ****
  • Posts: 451
    • View Profile
Re: SUM() problem?
« Reply #14 on: September 05, 2016, 12:20:29 pm »
my pleasure
 ;)