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: 
Not applicable

Use variable in expression

I have two variables defined

LET vCurrentWeek = Week(Today());

LET vLastWeek = vCurrentWeek-1;

And I have an expression to calculate revenue

=sum({$<Book={"EM EUROBONDS VOL MATCH"}>}IF(PURCHASE_SALE='P',-NOMINAL,NOMINAL)*PRICE/100)

How can I calculate revenue for last week by using my vLastWeek variable and adapting my expression?

12 Replies
MK_QSL
MVP
MVP

=sum({$<Book={"EM EUROBONDS VOL MATCH"}, Week = {"$(=vLastWeek )"}>}IF(PURCHASE_SALE='P',-NOMINAL,NOMINAL)*PRICE/100)

Not applicable
Author

I don't have a field called Week

how is that defined?

MK_QSL
MVP
MVP

Write below in script below your DateField

Week(YourDateField) as Week

Not applicable
Author

I don't have access to the load script. I'm am doing a binary load from another qvw

its_anandrjs
Champion III
Champion III

You can try write

Add this script to the expression Week(YourDateFieldHere) = {'$(=Week(Today() )-7 )'

=Sum({$<Book={"EM EUROBONDS VOL MATCH"}, Week(YourDateFieldHere) = {'$(=Week(Today() )-7 )'}>}

  IF(PURCHASE_SALE='P',-NOMINAL,NOMINAL)*PRICE/100)

Not applicable
Author

I get a blank result when I do that Anand

Not applicable
Author

Does my date field need to be in a certain format for that to work?

In my list boxes it appears as DD-MMM-YYYY

its_anandrjs
Champion III
Champion III

Try like

=sum({$<Book={"EM EUROBONDS VOL MATCH"}, Week(YourDateFieldHere) = {"$(=Week(Today( ))-7 )"}>}IF(PURCHASE_SALE='P',-NOMINAL,NOMINAL)*PRICE/100)

Not applicable
Author

It didn't work either. Blank result again

Is it possible my CalendarDate field may not be in the correct format, even though it displays correctly in the list box and tables? Would that make a difference?