Tip

@Select May not do what you think it will - Use @Subset


I had two related list fields in my document,

Item and Weight. My users wanted the total weight field to exclude the wight of Carbon Dioxide (Item Code "CO2"). This seemed simple. Find out the Item element number = "CO2", and subtract the value of the same element in the weight list from the original summed field..... But all was not what it seemed.


CODE:
Here was my initial code to get field TotalWeight:

Item Weight

Item01 10.00
CO2 20.00
Item02 30.00
Item03 40.00

Elem=@Member("CO2";Item);

Elem now contains the position in the array of the text "CO2", 2.

CO2Weight=@Select(Elem;Weight);

CO2Weight should now contain 20.00.

@Sum(Weight)-CO2Weight

The total weight without CO2's weight.

But, Aargghh, CO2Weight returned the entire list of numbers... 10.00 ; 20.00 ; 30.00
; 40.00


Anyway, after a lot of faffing about, doubting my work, checking the manuals,
banging my head against the desk etc I finally searched the lotus knowledge base
and found this at

http://www.support.lotus.com/sims2.nsf/802ee480bdd32d0b852566fa005acf8d/489569fb8e698275862565460072209a?OpenDocument&Highlight=2,%40Select 

"The @Select function in Notes 4.x does not provide the ability to return the Nth
item of an arbitrary list. It will work only if you specify your semicolon-separated
list explicitly when you write the formula. How can a given element of a list be
returned using formulas?

Solution:

Nested @Subset calls can achieve this, as follows:

@Subset(@Subset(list;N);-1)

Where N is a number representing which element you would like to select, with the
first element being number 1.

The inner @Subset call selects all elements of a list up to and including the number
you specify (1 through N). The outer @Subset selects just the last element of the
previous list (element N only).

In a similar way, you can access the Nth-to-last element of the list via:

@Subset(@Subset(list;-N);1)

In this case, the inner @Subset returns a list counting backwards from the end of the
list, consisting of N items, and the outer @Subset call returns the first of these (the
last element if N is 1, the second-to-last element if N is 2, etc."

WELL THANKS FOR TELLING US!!!

This was first published in November 2000

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.