4 Replies Latest reply: Jul 25, 2018 1:25 AM by Asfand Butt

# Confusion with using Sum function for different units

Hi,

i have the following expression that is causing some issues in Count.

Sum({<TransDate={'>=\$(=MonthStart(today(),-12))<=\$(=MonthEnd(today(),-1))'}>}\$(UnitValue))

\$(UnitValue) is a variable that either passes 1 or a value of TEUs e.g. if(\$(vUnits)=0,TEUs,1)

In case of passing TEUs the sum comes perfect whereas while passing 1, i just want the sum function to behav like count function and just gives a count of all rows but its giving a bigger count than it should be. My problem is i have to stick with Sum in my expression.

Any suggestions?

Thanks,

• ###### Re: Confusion with using Sum function for different units

May be you can do this

If(\$(vUnits) = 0,

Sum({<TransDate={'>=\$(=MonthStart(today(),-12))<=\$(=MonthEnd(today(),-1))'}>} TEUs),

Count({<TransDate={'>=\$(=MonthStart(today(),-12))<=\$(=MonthEnd(today(),-1))'}>} 1))

• ###### Re: Confusion with using Sum function for different units

You are right about it and i have already considered it the last solution. Ideally i want to do it using Sum() as i have so much conditional expressions and i don't want to do it that way it will increase a lot of code.

• ###### Re: Confusion with using Sum function for different units

Hi,

with 1 :

it will count all rows of your database I think because you have no field

with that :

if(\$(vUnits)=0,TEUs,TEUs-TEUs+1)

it will count all not null rows of TEUs

(for the fun)

prefer Sunny's solution it's clean

• ###### Re: Confusion with using Sum function for different units

That looks cool and seem to have worked.