Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
snancyiv
Contributor III
Contributor III

Previous Quarter calculation

Hi everyone!

I'm trying to calculate the change in two quarters, I think I'm getting close but not sure what else I am missing in my formula and hoping that someone can help. Basically, user will select a quarter and the KPI will show current value and what the change was from prior quarter. 

Here are the sales figures:

Current Quarter Sales: 356

Previous Quarter Sales: 524

I created two variables to return the start dates, one for current quarter and another for previous quarter:

vCurrentQuarter: date(min([Year Month]),'YYYY-MMM')

vPreviousQuarter: date(addmonths(min([Year Month]),-3),'YYYY-MMM')

Calculation for Previous quarter sales: sum(${<'$(vCurrentQuarter)' ={"$(vPreviousQuarter)"}>} Sales)

The calculation keeps giving me current quarter sales. What am I missing? Thanks in advance!

Labels (2)
11 Replies
BrunPierre
Partner - Master
Partner - Master

@snancyiv Once you have a well-formatted date field, try these

Current: Sum({<[Date Field]={">=$(=Quarterstart(today(1)))<=$(=Quarterend(today(1)))"}>}Sales)

Previous: Sum({<[Date Field]={">=$(=Quarterstart(today(1),-1))<=$(=Quarterend(today(1),-1))"}>}Sales)

snancyiv
Contributor III
Contributor III
Author

Hi @BrunPierre ,

I'm still getting current quarter values. For more reference, the filter to to select quarters is based on the quarter start date, "QuarterStart" which is calculated field in the script as Quarterstart(Date).

BrunPierre
Partner - Master
Partner - Master

Provide some samples of the data.

snancyiv
Contributor III
Contributor III
Author

Removed sensitive info from the original. Please filter "YearQuarter" on 2022-Q4 when you open it to see my example.

snancyiv
Contributor III
Contributor III
Author

The association is on Date to Discharge Date. When you filter on 2022-Q4, it should be:

Current Quarter TotalNumerCase: 107

Previous Quarter TotalNumerCase: 162

BrunPierre
Partner - Master
Partner - Master

Maybe this

Current Quarter: Sum({<DischargeDate={">=$(=QuarterStart(Max(DischargeDate),-1))<=$(=AddMonths(Max(DischargeDate),-3))"}>}TotalNumerCase)

Previous Quarter:Sum({<DischargeDate={">=$(=QuarterStart(Max(DischargeDate)))<=$(=AddMonths(Max(DischargeDate),0))"}>}TotalNumerCase)

peter_brown_2-1663046745255.png

krishna_p
Contributor II
Contributor II

Hi,

Current Quarter : sum({<[Date-DischargeDate]={">=$(=QuarterStart(Max([Date-DischargeDate]))) <=$(=QuarterEnd(max([Date-DischargeDate])))"}>}TotalNumerCase)

krishna_p_0-1663052981603.png

Previous Quarter : sum({<[Date-DischargeDate]={">=$(=QuarterStart(Max([Date-DischargeDate]),-1)) <=$(=QuarterEnd(max([Date-DischargeDate]),-1))"}>}TotalNumerCase)

krishna_p_1-1663053103380.png

Thanks,

Krishna

snancyiv
Contributor III
Contributor III
Author

I still get the same amount as current quarter for previous calculation. 😞

snancyiv
Contributor III
Contributor III
Author

Still getting the same amount as current quarter