Summing values in repeated sections in Orbeon - orbeon

I have a problem when it comes to suming values from a repeated section. Specifically, when I have a repeated section in the orbeon builder with a control that has a value I can easily sum the values of these sections in a different control using sum($control-1) - in the calculated value. When inputing values in the form preview the sum is correct in my control with the summed value.
Unfortunately, when I add a section using the +Insert Below button in the form preview while testing the form the sum() function doesn't work anymore. In the control with this calculated value nothing is shown. Is there a different way to get the sum of values from repeated sections or is this a bug in orbeon?

Once you add a new section while testing the form the sum() function doesn't work anymore, because it adds a empty element to the node-set.
In XPath, when using the sum function, the value of each node is determined by trying to converting it to a number (number()), if there is a empty value, it's gonna convert to NaN, thus in the control with this calculated value nothing is shown by Orbeon.
A different way that would work would be to use the expression like: sum($control-1[text()]) . This way you are testing if the node has content before trying to sum it, so it's always gonna work.

Related

Sum returned values from arrayformula()?

I have a long list of values in a row that I need to perform several functions/vlookups on, multiply them all together and then sum all the final values. There are over 50 different values in a row so I'm trying to come up with a way to do this without manually typing out vlookups for each column.
Here is the formula I put together, however it seems to not be returning the correct value:
=sum(arrayformula(vlookup(offset($A$1,0,{9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54}),Input!$E:$F,2,FALSE)
*offset(indirect("$A"&ROW()),0,{9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54})))
+F6+BD6
It's as if it's doing what I want for some of the values, but not summing them all. Debugging this is an absolute pain, so I'm wondering if I'm even going about this in the right way.
Is there a better way to go about this? I'm wondering if the problem is that I've got two sets of arrays embedded in this function.

custom vaadin-grid filter for Polymer 1.0

I’m using the vaadin-grid#^3.0.2 in my polymer 1.0 project.
But I’m looking to create an on/off toggle button that will filter a column based on if the text in two columns are not a match. So if a row in column 1 contains text=“1.1.1” and that same row in column 2 contains text = “2.1.1" then I would keep this row displayed, and hide all other rows. I want to do this in javscript. I’m very new to the vaadin-grid (had so much previous experience with iron-data-table). Anyone have a suggestion on how I can access the filter function?
image of 2 different columns of versions
I tried using the standard filter element but it's too limiting because it only allows me to do string based filtering on just one-specific column, but it's not built so I can do a comparison between strings in two different columns.
<vaadin-grid-filter path="version" value="[[_filterVersion]]">
<input value="{{_filterVersion::input}}">
</vaadin-grid-filter>
One simple way to do filtering that looks at the values of two columns is to not use vaadin-grid-filter, rather just have a input field outside the grid, then filter the array bound to the grid's items property as needed.
<vaadin-textfield on-value-changed="_filterMethod"></vaadin-textfield>
_filterMethod(evt) {
this.gridItems = this.allItems.filter(it => it.col1 !== it.col2);
}
Although I may not fully understand your question as I don't why you are using an input field instead of a button. This filter method approach should work equally well if you call it from a button instead.

Orbeon 4.10 - Fill Repeat Repeated Grid from Checkbox

I want to fill a Repeated grid with value from a checkbox.
User would select multiple items from a checkbox then hit a button to add the required number of rows and set the value of a field in each iteration according to what was checked
I would need something like a foreach checked value : run this code
I'm having a hard time finding documentation about this kind of Xforms. I did find some info about Iterate and Iterator that seems promising but i failed to make that work.
I was able to add the required number of row to my grid but then im not sure how to use xf:setvalue set the value of each row.
Any help appreciated.
I think a combination of the iterate attribute to create a loop, the xxf:split() function to get the selected values as a sequence you can iterate on, and xf:insert to create elements will do the trick. See this example, which does the following:
And here is an example which does the same, but for a form created with Form Builder. In this case, the result is as follows:

Google Sheets - get the right-most value of a row

I have a sheet where the columns are months in a year and the rows are various metrics. Every month, we add another column on the right.
I need something that I can give a ROW and it will always return the right most value. That is, it automatically updates whenever we add a column for a new month.
There's a few ways of doing it, but one way (considering row 2 in this example):
=FILTER(2:2,COLUMN(2:2)=MAX(FILTER(COLUMN(2:2),LEN(2:2))))
I was very happy to have found #AdamL's answer and it did make my day, but I have since found a simpler way that works fine for my data sample, and that is using the LOOKUP function.
The LOOKUP function will look for a certain value in a given range, but if you pass it a humongous value, a value that is over your data range, it returns the last, rightmost value by default.
The answer is then very simple, just pass it the range - or row if that's what you need - and a huge value (many people do this using the biggest number that Excel can handle, but Google sheets is not Excel, and since I don't know what is the biggest number Google sheets can handle, I'll just give it a value well outside of my data set). Assuming you need to lookup into the entire row number 2:
=LOOKUP(999999999,2:2)
And that's it.
This function will throw an error if there isn't any data, so if you (like me) need to get that particular value only if it exists, you can combine this with a simple IF function:
=IF(ISERROR(LOOKUP(999999999,2:2)),"EMPTY",LOOKUP(999999999,2:2))
You can replace the string "EMPTY" with any value or function you want in there if the LOOKUP function returns an error.
I hope this simpler method is of any help, and thanks again to #AdamL for his original answer.
Adding this one for future readers. The formula I found years ago for obtaining the rightmost value was:
=index(2:2,1,COUNT(2:2))
However for each blank cells in amongst the cells with data, the returned value is the Nth last value (2 blank cells in row 2 and the formula will return the 3rd last value from the right, not the rightmost value). It appears to work, but won't be accurate in all cases.
As such, I do not recommend this formula as you can not depend on it if ever there will be an empty cell before the right-most within your data.

Orbeon - empty value as 0

I have many input fields in Orbeon in Form builder as war1, war2 , war3, and not all fields have to be filled. I want to make a sum of this fields (I can't make them repeatable because I want to reset it via web service), but when some of the fields are empty, the sum doesn't display. Using an initial value doesn't resolve the problem because I want to set values via a web service, and sometimes the values returned by the service are empty string.
Assuming your fields are named war1, war2, war3, use:
sum(($war1, $war2, $war3)[string() castable as xs:decimal], 0.0)
And for some background on this, see the blog post Formulas for summing values, done right, which is exactly about this topic. (The very fact that there is a blog entry about this tells you that this is rather subtle, which makes your question all the more justifiable.)

Resources