Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
reporting_neu
Creator III
Creator III

Get SUM of current Year Month and Last Year until same Month

Hello,

I'm creating a bar chart. This should display the values ​​of the months from the current year with the values ​​of the same months in the past year. However, I can't manage that not all values ​​from the past year are displayed. I only need these up to the current month. So today only January to February.

My formula looks like this:

 

SUM({1<Sales.Year={$(=max(Sales.Year)-12),$(=max(Sales.Year))}, Group = {'ABC'}>} [Sales])

 

I also have the following times to choose from:

  • Year
  • YearMonth = 202401 (2024 January)
  • MonthYear = 012024 (January 2024)

How can I limit the last year (the months) so that only the months up to today are shown?

Qlik Sense.png

Labels (3)
1 Solution

Accepted Solutions
reporting_neu
Creator III
Creator III
Author

Thank you for your support. Unfortunately, none of the formulas led me to the desired solution.

But I still found a solution. I merged the year and month in the script and generated a date from it:

MakeDate(Year, Month, 1) as Sales.Date

I was then able to combine the formulas for the current year and the last year so that I could display both values together in one diagram:

SUM({1<Sales.Date = {">=$(=YearStart(MAX(Sales.Date)))<=$(=MonthEnd(MAX(Sales.Date)))"}, Group= {'ABC'}>}Sales.Sales)

+

SUM({1<Sales.Date = {">=$(=YearStart(MAX(Sales.Date),-1))<=$(=MonthEnd(MAX(Sales.Date),-12))"}, Group= {'ABC'}>}Sales.Sales)

 The result now looks like this:

Unbenannt.png

View solution in original post

3 Replies
anat
Master
Master

=SUM({<YearMonth = {"<=$(=Date(MonthStart(Today()),'YYYYMM')),'YYYYMM'))>=$(=Date(MonthStart(Today(),-12),'YYYYMM'))"}>}Amount)

Chanty4u
MVP
MVP

Try this

SUM({<Sales.Year = {"$(=Max(Sales.Year))"}, 

     Sales.MonthYear = {"<=$(=Max(Sales.MonthYear))"}, 

     Group = {'ABC'}>} [Sales])

reporting_neu
Creator III
Creator III
Author

Thank you for your support. Unfortunately, none of the formulas led me to the desired solution.

But I still found a solution. I merged the year and month in the script and generated a date from it:

MakeDate(Year, Month, 1) as Sales.Date

I was then able to combine the formulas for the current year and the last year so that I could display both values together in one diagram:

SUM({1<Sales.Date = {">=$(=YearStart(MAX(Sales.Date)))<=$(=MonthEnd(MAX(Sales.Date)))"}, Group= {'ABC'}>}Sales.Sales)

+

SUM({1<Sales.Date = {">=$(=YearStart(MAX(Sales.Date),-1))<=$(=MonthEnd(MAX(Sales.Date),-12))"}, Group= {'ABC'}>}Sales.Sales)

 The result now looks like this:

Unbenannt.png