 Level 1

0% to Level 2

Tip /

to gain points, level up, and earn exciting badges like the new
Mission!

View all

SOLVED

## Count variables - duplicates count as 1 and multiply with max. value  Level 2

Hello,

I have a little issue and don't know how to solve it. I tried following code with FormCalc to calculate the daily allowance, but didn't work properly.

I need to count the real amount of days, which means if the client needs two rows for one day it must only calculate it as one day.

The second thing (what I couldn't even start to program) is that it must multiplay the maximum quantity of technicians with each day.

Example:

3 technicians          18.03.2018          09:00 - 12:00

5 technicians          18.03.2018          13:00 - 16:00

Quantity of daily allowance: 5 technicians * 1 day = 1

I'm frustrated and hope anyone can help me out.

Thanks in advance, I appreciate what you are doin guys.

Best regards,

Markus

For the code and pictures of hierarchy see below.

ServiceReport.Hauptseite_kalk.Kalk.Kalk_2.Kalk2.dailyallowance.Quty::calculate - (FormCalc, client)

var val = Kalk1[*].Date_einf.rawValue

var spval = Kalk1[i].Date_einf.rawValue

var cou = Count(Kalk1[*].Date_einf)

var one = 0

var two = 0

for i=0 upto cou do

if (Count(val eq spval) eq 1) then

one =+  Count(val eq spval)

// adds value 1 for days that are counted once

elseif (Count(val eq spval) ne 1) then

two =+ 1 / Count(val eq spval)

// explanation: if I count a one day two times e.g.:

// 18.03.2018

// 18.03.2018

// It would make one day counted as two, therefore I divide 1 / days

// 2 * (1 / 2) = 1 day -> Workaround

endif

endfor

this.rawValue = one + two 1 Accepted Solution  Level 2

found a work-a-round:

in the nested table i inserted a foot row that calculates the maximum. To not show the row I made it 0,001 cm high.

After that I just summed it through Formcalc and IT WORKS!!

13 Replies  Level 2

Changed a little bit and tried it with javascript - didn't work either.

I changed the hierarchy so all rows are on the same "parent" level.

It shows a syntaxerror in last row -> unclosed token - I don`t know how to fix it

Tried it with this code:

var Anzahl_K = 0 ;

var Rows = parent.parent.resolveNodes("Kalk1[*]") ;

for (var i = 0; i =< Rows.length; i++) {

var y = i - 1 ;

if (parent.parent.resolveNodes("Kalk1[" + Z + "].Date_einf").rawValue == parent.parent.resolveNodes("Kalk1[" + y +      "].Date_einf").rawValue)

{}

else {

Anzahl_K ++

}

this.rawValue = Anzahl_K  Level 7

I see a couple things that are interesting/concerning. what do you qualify as a day? I see only 3 hours per technician. Is that considered a day? How are you creating the form inputs? is it in a table? Will only one day be used per form or table?

The way I would approach it is to loop through the date first. Find the same dates then go to the next column/field and add the number of technicians. The harder thing is determining what constitutes a days worth of work.  Level 2

Hello,

There is no restriction for the min. working hours, this is usually no problem. However I'll try to explain it a little bit better:

On the same day:

3 technicians travel to perform service tasks

another 2 are already at the location = 5

Now I already use two rows with the same date -> One for travel, one for work

For all 5 technicians I want to calculate the daily allowance, no matter if travel time or worktime, but I mustn't calculate the daily allowance for two days and 8 technicians, I want to calculate it for 5 technicians and one day.

Hope this helps. Do you have a short example for the loop? Already tried to develop a loop, but didnt't work.

Best regards,

Markus  Level 7

I guess I understand that. You would need to loop through the dates and get all the technicians for a date.  Level 2

Yeah thats what I wanted.

You got any idea how to do that?

Markus  Level 7

I would have to think on it. The issue really will be how is the form set up. For example if the form is only used for one day regardless of how many techs you send out then it becomes easy but if the form captures techs over a number of days, it becomes a bit more complex. In your example (see below) you have 3 techs from 9-12 and 5 from 13-16. Is that a total of 8? your sample says 5 does that mean it is 3 + 2 more to be 5?

Also based on the form layout what if there are more techs needed on 19.03.2018? do they get added to the total or is that another day? if so how do you display that on the form?

Example:

3 technicians          18.03.2018          09:00 - 12:00

5 technicians          18.03.2018          13:00 - 16:00

Quantity of daily allowance: 5 technicians * 1 day = 1  Level 2

It was meant that we have Service technicians on the field, but sometimes additional technicians are required, The additional technicians will charge the travel time. However in the work time all technicians that are working are included.

In any case they will work several days (timespan can be 3 up to 14 days)

Markus  Level 7

And you want to calculate for each day?

Day 1 total

Day 2 total

etc?

How will you do this in the form?  Level 2

No I want to sum the total

So loop the days to get no duplicates and take the max number of technicians for the row.

After that I want to sum all max valus in one field.

With this field the total daily allowance will be calculated.  Level 7

Not sure I fully follow but wouldnt it be easier to just add a row for the next set of technicians and then get a total?  Level 2

Hey,

Today I tried this, but I still need to develop a loop for the max number of technicians for each day.

See hirarchy and example below. Pls ignor the kilometer mistake, minor defect.

However I have to loop through Kalk.Kalk1 and find the rows. That's the easy part:

var number_of_rows = Kalk._Kalk1.count;

But how do I develop the loop through the subform (Kalk.Kalk1.Tabelle1.Kalk)? I tried following, but didn't work. Especially the bold part doesn't work as planned.

Best regards,

Markus

__________________________________________________________________________________

var total = 0;

for(i=0, i==ServiceReport.Hauptseite_kalk.Kalk._Kalk1.count; i++) {

total += Math.max(ServiceReport.Hauptseite_kalk.Kalk.resolveNodes("Kalk1[" + i + "]").Kalk[*].Quty_einf.rawValue)

}

this.rawValue = total;

___________________________________________________________________________________    Level 2

found a work-a-round:

in the nested table i inserted a foot row that calculates the maximum. To not show the row I made it 0,001 cm high.

After that I just summed it through Formcalc and IT WORKS!!  Level 7

NICE! 