Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us in NYC Sept 4th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
JR4
Contributor II
Contributor II

Current and Previous Month in table, not working

Hi everyone,

I'm building charts for Month over Month data, but I'm having some issues getting it to work right. Below are snippets of my chart, the first is the default appearance, the second is when I select the month of March. It should show me March 2025 and Feb 2025, but it won't. Below the images is the current set analysis I have in my expressions:

Default, shows current month and previous monthDefault, shows current month and previous monthWhen I select March, it does not show me current (selected) month and previous monthWhen I select March, it does not show me current (selected) month and previous month

Current Year, Current Month: (works fine)
{$<Year={$(=If(GetSelectedCount(Year) > 0, Concat(DISTINCT Year, ','), year(date(today()))))},
Month={$(=If(GetSelectedCount(Month) > 0, Concat(DISTINCT Month, ','), month(date(today()))))}

Current Year, Previous Month: (Works on default, but not when filtered/selected)
{$<Year={$(=If(GetSelectedCount(Year) > 0, Concat(DISTINCT Year, ','), year(date(AddMonths(today(), -1)))))},
Month={$(=If(GetSelectedCount(Month) > 0, Concat(DISTINCT Month, ','), month(date(AddMonths(today(), -1)))))}

Any help would be greatly appreciated! Thanks in advance!!

Labels (5)
1 Solution

Accepted Solutions
SRA
Partner - Creator
Partner - Creator

Hi,

If we consider the loading script (I added data from Feb.) :

Source:
LOAD * INLINE [
Date, Metric, Value
2025-02-01, Loads, 100
2025-02-01, Avg Price, 2.13
2025-02-01, Pallets Sold, 34567
2025-02-01, Revenue, 11234
2025-03-01, Loads, 125
2025-03-01, Avg Price, 6.83
2025-03-01, Pallets Sold, 54026
2025-03-01, Revenue, 306113
2025-04-01, Loads, 48
2025-04-01, Avg Price, 8.41
2025-04-01, Pallets Sold, 20349
2025-04-01, Revenue, 163381
];
 
Data:
Noconcatenate Load
Date(Date#(Date, 'YYYY-MM-DD')) as YourDate,
    Metric,
    Value
Resident Source;
 
Drop Table Source;
 
Measure for current month (considering 'current' will be the last selected... or the last if no selection) :
=Sum( {<YourDate={">=$(=MonthStart(Max(YourDate))) <=$(=MonthEnd(Max(YourDate)))"}>} Value)

Description of the measure : =MonthName(Max(YourDate))

Measure for previous month (considering'previous' will be the previous tu the last selected...) :
= Sum( {1 <YourDate={">=$(=MonthStart(Max(YourDate), -1)) <=$(=MonthEnd(Max(YourDate), -1))"}>} Value)
Description of the measure :=MonthName(MonthStart(Max(YourDate),-1))

Selection made on a dimension 'Month' : =MonthName(YourDate)
Remark : I did that like this to get a quick result... but would be better to have a calendar and use a dedicated field for the month.

If you select Apr 2025 (Or make no selection) :

SRA_2-1744107636570.png

If you select Mar 2025 :

SRA_1-1744107609052.png

Let me know if this answer is helping you (if yes, please tick the answer as a solution).

Regards

 

View solution in original post

1 Reply
SRA
Partner - Creator
Partner - Creator

Hi,

If we consider the loading script (I added data from Feb.) :

Source:
LOAD * INLINE [
Date, Metric, Value
2025-02-01, Loads, 100
2025-02-01, Avg Price, 2.13
2025-02-01, Pallets Sold, 34567
2025-02-01, Revenue, 11234
2025-03-01, Loads, 125
2025-03-01, Avg Price, 6.83
2025-03-01, Pallets Sold, 54026
2025-03-01, Revenue, 306113
2025-04-01, Loads, 48
2025-04-01, Avg Price, 8.41
2025-04-01, Pallets Sold, 20349
2025-04-01, Revenue, 163381
];
 
Data:
Noconcatenate Load
Date(Date#(Date, 'YYYY-MM-DD')) as YourDate,
    Metric,
    Value
Resident Source;
 
Drop Table Source;
 
Measure for current month (considering 'current' will be the last selected... or the last if no selection) :
=Sum( {<YourDate={">=$(=MonthStart(Max(YourDate))) <=$(=MonthEnd(Max(YourDate)))"}>} Value)

Description of the measure : =MonthName(Max(YourDate))

Measure for previous month (considering'previous' will be the previous tu the last selected...) :
= Sum( {1 <YourDate={">=$(=MonthStart(Max(YourDate), -1)) <=$(=MonthEnd(Max(YourDate), -1))"}>} Value)
Description of the measure :=MonthName(MonthStart(Max(YourDate),-1))

Selection made on a dimension 'Month' : =MonthName(YourDate)
Remark : I did that like this to get a quick result... but would be better to have a calendar and use a dedicated field for the month.

If you select Apr 2025 (Or make no selection) :

SRA_2-1744107636570.png

If you select Mar 2025 :

SRA_1-1744107609052.png

Let me know if this answer is helping you (if yes, please tick the answer as a solution).

Regards