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

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
rfigueroa
Contributor III
Contributor III

Expression to compare with first value

Hi,

In the example attached, I would like to add a fourth column so their value will be the current Quantity minus the Quantity value from the first Purchase for the same Product.

For example for product A, Fx will be Qty - 10 which is the value from the first purchase:

productID  dtPurchase  Quantity  Fx

   A       01/01/2000       10      0

   A       01/02/2000       9       1

   A       01/03/2000       8       2

I know that's very simple for you guys...hope can you help me.

Thanks in advance.

Cheers.

Roberto

1 Solution

Accepted Solutions
johnw
Champion III
Champion III

This seems to be working, though I didn't check it particularly carefully:

Quantity-firstsortedvalue(total <productID> Quantity,dtPurchase)

View solution in original post

4 Replies
matt_crowther
Specialist
Specialist

Roberto,

Try top(Quantity) as you'r expression - it works for me in your example file.

You can of course use top(total Quantity) to take the very first record.

Hope that helps,

Matt - Visual Analytics Ltd

rfigueroa
Contributor III
Contributor III
Author

Thank you Matt, but seems the results change when we change the order. I need an expressions that returns always the first Quantity value from the first purchase for each product.

Robert.

johnw
Champion III
Champion III

This seems to be working, though I didn't check it particularly carefully:

Quantity-firstsortedvalue(total <productID> Quantity,dtPurchase)

rfigueroa
Contributor III
Contributor III
Author

works perfect! thank you John.