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: 
alexis
Partner - Specialist
Partner - Specialist

Date calculation help

I have the following formula:

= sum({$<[TransactionLinesDate] = {'>=$(=Date(vStartDate))<=$(=Date(vEndDate))'},

[TransactionLinesType] = {'I', 'C', 'T'}>}

TransactionLinesAmount)

vStartDate and vEndDate are typically the beginning of the month so we may have value 01/01/2015 (42005) and 01/02/2015 (42036).

I want to repeat the above calculation but for the month before - in other words instead of calculating for start of January until start of February, I want start of December 2014 to start of January 2015....

In other words I want vStartDate and vEndDate to be adjusted by one less month.

I have even tried the following and cannot get it to work...

:

= sum({$<[TransactionLinesDate] = {'>=$(=Date(vStartDate - 31))<=$(=Date(vEndDate - 31))'},

[TransactionLinesType] = {'I', 'C', 'T'}>}

TransactionLinesAmount)

Any help would be greatly appreciated...

1 Solution

Accepted Solutions
alexis
Partner - Specialist
Partner - Specialist
Author

Thanks Anbu

I adapted what you suggested and got the desired result with the following - for some reason I was not getting the desired result with Date# and the formatting:

sum({$<[TransactionLinesDate] = {'>=$(=AddMonths(Date(vStartDate),-1))<=$(=AddMonths(Date(vEndDate),-1))'},

[TransactionLinesType] = {'I', 'C', 'T'}>}

TransactionLinesAmount)

Thanks

Alexis

View solution in original post

4 Replies
anbu1984
Master III
Master III

= sum({$<[TransactionLinesDate] = {'>=$(=AddMonths(Date#(vStartDate,'DD/MM/YYYY'),-1))<=$(=AddMonths(Date#(vEndDate,'DD/MM/YYYY'),-1))'},

[TransactionLinesType] = {'I', 'C', 'T'}>}

TransactionLinesAmount)

alexis
Partner - Specialist
Partner - Specialist
Author

Thanks Anbu

I adapted what you suggested and got the desired result with the following - for some reason I was not getting the desired result with Date# and the formatting:

sum({$<[TransactionLinesDate] = {'>=$(=AddMonths(Date(vStartDate),-1))<=$(=AddMonths(Date(vEndDate),-1))'},

[TransactionLinesType] = {'I', 'C', 'T'}>}

TransactionLinesAmount)

Thanks

Alexis

anbu1984
Master III
Master III

If the values stored in vStartDate and vEndDate are date, then you can directly use Addmonths() without Date()

alexis
Partner - Specialist
Partner - Specialist
Author

vStartDate and vEndDate are numeric (e.g. 42005 for 01/01/2015) hence why I "Date" them and then deduct 1 month as you suggested.

Thanks again

Alexis