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

Announcements
Qlik GA: Multivariate Time Series in Qlik Predict: Get Details
cancel
Showing results for 
Search instead for 
Did you mean: 
Ron1
Partner - Creator
Partner - Creator

Previous Month Data Generator in QlikSense

I have a source table. In QlikSense there will be two filter panes (Year , MonthNumber)

There are below three requirements:

1) When there will be no selection the previous month(from current month) data will be visible.

2) If user selects some MonthNumber from Filter, in chart only previous month(selected month -1) data should be seen.

3) If user select '1' as MonthNumber, previous year December Data should be seen.

Product IDProduct CategoryYearMonthMonthNumberSales
1Electronics2018Dec12123
2Books2019Jun61231
3HomeStuffs2017Feb222
4Appliances2019Dec1232
5Electrical2019Jan112
6Electronics2016Mar313
7Books2017Apr454
8Electronics2019May532
9Electronics2017Jan614
10Appliances2019Jul712
11HomeStuffs2016Dec1256
1 Solution

Accepted Solutions
Vegar
MVP
MVP

You will need to create a field that increase in value for each month, like YearMonth.  See an example on how to do it in my script below. 

(In my solution I assume that current month is equal to the latest year month in the data set. )

 

 

LOAD 
  [Product ID],
  [Product Category],
  Year,
  Month,
  monthname(MakeDate(Year, MonthNumber)) as YearMonth,
  //MonthNumber,
  Sales 
Inline [
Product ID,	Product Category,Year,Month,MonthNumber,Sales
1,			Electronics,	2018, Dec,	12,			123
2,			Books,			2018, Jul,	7,			1231
3,			HomeStuffs,		2017, Feb,	2,			22
4,			Appliances,		2019, Jun,	6,			32
5,			Electrical,		2019, May,	5,			12
6,			Electronics,	2016, Mar,	3,			13
7,			Books,			2018, Jun,	6,			54
8,			Electronics,	2016, May,	5,			32
9,			Electronics,	2017, Jan,	1,			14
10,			Appliances,		2018, Nov,	11,			12
11,			HomeStuffs,		2016, Dec,	12,			56];

 

 

 

When you have this field you can use it in a set expression in your application.

 

 

sum({<
	Year,  //ignore selections on year
	Month, //ignore selection in month
	YearMonth={'$(=monthname(max(YearMonth),-1))'} //YearMonth should be previous of selected max month.
	>}Sales)

 

 

 

This will give you this value selecting Jan, 2018 will give you these values were previous month is the expression above.

image.png

View solution in original post

3 Replies
Ron1
Partner - Creator
Partner - Creator
Author

Please treat below as source table

Product IDProduct CategoryYearMonthMonthNumberSales
1Electronics2018Dec12123
2Books2018Jul71231
3HomeStuffs2017Feb222
4Appliances2019Jun632
5Electrical2019May512
6Electronics2016Mar313
7Books2018Jun654
8Electronics2016May532
9Electronics2017Jan114
10Appliances2018Nov1112
11HomeStuffs2016Dec1256

 

Vegar
MVP
MVP

You will need to create a field that increase in value for each month, like YearMonth.  See an example on how to do it in my script below. 

(In my solution I assume that current month is equal to the latest year month in the data set. )

 

 

LOAD 
  [Product ID],
  [Product Category],
  Year,
  Month,
  monthname(MakeDate(Year, MonthNumber)) as YearMonth,
  //MonthNumber,
  Sales 
Inline [
Product ID,	Product Category,Year,Month,MonthNumber,Sales
1,			Electronics,	2018, Dec,	12,			123
2,			Books,			2018, Jul,	7,			1231
3,			HomeStuffs,		2017, Feb,	2,			22
4,			Appliances,		2019, Jun,	6,			32
5,			Electrical,		2019, May,	5,			12
6,			Electronics,	2016, Mar,	3,			13
7,			Books,			2018, Jun,	6,			54
8,			Electronics,	2016, May,	5,			32
9,			Electronics,	2017, Jan,	1,			14
10,			Appliances,		2018, Nov,	11,			12
11,			HomeStuffs,		2016, Dec,	12,			56];

 

 

 

When you have this field you can use it in a set expression in your application.

 

 

sum({<
	Year,  //ignore selections on year
	Month, //ignore selection in month
	YearMonth={'$(=monthname(max(YearMonth),-1))'} //YearMonth should be previous of selected max month.
	>}Sales)

 

 

 

This will give you this value selecting Jan, 2018 will give you these values were previous month is the expression above.

image.png

Ron1
Partner - Creator
Partner - Creator
Author

Thank you very much. It worked..:)