Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us in Bucharest on Sept 18th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Calculate a spread in Expression

Hi there,

I'm trying to graph a spread between 2 series.

You'll find enclosed an exemple file.

What i'm trying to do is to add a curve in the graph corresponding to the sprerad between 2 maturities. I mean that if you choose for exemple M1 & M2, the curve should show M2-M1 price (or M1-M2). And if i change selection to M3&M1 the curve will be M3-M1 or M1-M3.

Is anyone already try to do it.

Thanks for your help.

1 Solution

Accepted Solutions
Not applicable
Author

Ok i foundthe answer.

In fact, it works well but you have to be careful with the GetFieldSelections statement.

If you don't put a delimiter, it use the default one which is ', '. that mean that there is a space between the coma and the second selection.And then the subfield statement for the second field keep the space.

So 2 solutions:

1/ use the Trim function to supress blank.

2/ Precise the delimiter ,e.g. ',' for example and then you will have no space after the delimiter.

Tricky things.

View solution in original post

4 Replies
Not applicable
Author

I know that i must use Set Analysis to do so, but i didn't succeed.

No one have already try to compare series, like this ?

Not applicable
Author

Ok fine, I try something and think i'm on the right way.

I can get the price for selected maturity doing the folowing:

=sum({<MATURITY={"$(=GetFieldSelections(MATURITY))"}>} PRICE)

This only works when we have 1 maturity selected.

The GetFieldSelections function can return all the selection that mean that if i have 2 maturity, GetFieldSelections must return M1,M2.

The question is now, how to get the first maturity and the second one from this expression?

Thxs again for your help.

Not applicable
Author

ok one step forward but this time really don't no how to solve it.

I used the subfield function to get the 2 distinct maturity.

The expression SubField(GetFieldSelections(MATURITY),',',2) give me the 2nd selected maturity (for example M2)

But the following expression:

=Sum({<MATURITY={"$(=SubFieldGetFieldSelectionsMATURITY),',',2))"}>} PRICE)

do not return the Price for maturity M2 and just note: No data to display..

any idea ?

Not applicable
Author

Ok i foundthe answer.

In fact, it works well but you have to be careful with the GetFieldSelections statement.

If you don't put a delimiter, it use the default one which is ', '. that mean that there is a space between the coma and the second selection.And then the subfield statement for the second field keep the space.

So 2 solutions:

1/ use the Trim function to supress blank.

2/ Precise the delimiter ,e.g. ',' for example and then you will have no space after the delimiter.

Tricky things.