Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
tomovangel
Partner - Specialist
Partner - Specialist

Get previous month/year selected dates

Hello dear Qlikers !

So my client wanted to have a CY/PY set analysis so he can look his sales during previous periods .

I have set analysis for:

week: Sum({<Week = {"$(=week(max(Date)-7))"}>}SalePrice)

and for the same month but previous year
=sum({<Year={$(=max(Year),-1)},Month={$(=month(max(Date)))}>}SalePrice)

But now my requirements are different.

My client wants to choose between set of dates,  and see the previous set of dates month/year
for example

02/01/2017 until 03/15/2017 (MM/DD/YYYY)  ( basically the whole february + 15 days from march)

And he wants to see for the previous period of this selected dates, which in this example will sales for 01/01/2017 until 02/15/2017( the whole january + 15 days from february)

Another example is .
from  07/07/2017 until 07/18/2017 - Selected Dates
from  06/07/2017 until 06/18/2017 - Previous dates ( automatically calculated)


I have tried using variables for StartDate and EndDate and input extension, but it crashes so my client doesn't want to use extensions anymore.


What is the workaround that you have found?

Thanks in advance for the response

Best Regards, Angel Tomov Junior Qlik Developer

23 Replies
sunny_talwar

I think you might have missed the closing parenthesis for the first dollar sign expansion

Sum({<Date = {">=$(=Date(AddMonths(Min(Date), -1), 'MM/DD/YYYY'))<=$(=Date(AddMonths(Max(Date), -1), 'MM/DD/YYYY'))"}>}SalePrice)

Thiago_Justen_

Absolutelly right Sunny. I forgot it.

My bad

Thiago Justen Teixeira Gonçalves
Farol BI
WhatsApp: 24 98152-1675
Skype: justen.thiago
tomovangel
Partner - Specialist
Partner - Specialist
Author

Screenshot_2.png

your expression is column 3

sunny_talwar

Date format is DD-MM-YYYY instead of DD/MM/YYYY.....

Sum({<Date = {"$(='>=' & Date(AddMonths(Min(Date), -1), 'DD-MM-YYYY') & '<=' & Date(AddMonths(Max(Date), -1), 'DD-MM-YYYY'))"}>}SalePrice)

tomovangel
Partner - Specialist
Partner - Specialist
Author

Screenshot_4.png

okay, now changed the format of date in both columns, Yours and Thiago's, but it still doesn't sum the SalePrice.

tomovangel
Partner - Specialist
Partner - Specialist
Author

Perhaps, the problem lies somewhere in the Date field?

sunny_talwar

This might be stupid question but, is your date field called date or is it called something else?

tomovangel
Partner - Specialist
Partner - Specialist
Author

its called Date

Thiago_Justen_

What  about not formatting date:

Sum({<Date = {">=$(=AddMonths(Min(Date), -1))<=$(=AddMonths(Max(Date), -1))"}>}SalePrice)

Thiago Justen Teixeira Gonçalves
Farol BI
WhatsApp: 24 98152-1675
Skype: justen.thiago
tomovangel
Partner - Specialist
Partner - Specialist
Author

Yes, so the problem was with the formating of the dates and maybe my date field.

I am going to mark all answers helpful >
1 more question if i use

Sum({<Date = {">=$(=AddMonths(Min(Date), -12))<=$(=AddMonths(Max(Date), -12))"}>}SalePrice)



Will it give me previous year of selected dates ?

Thank you all for the time