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: 
Ranjanac1
Contributor II
Contributor II

Need data for Previous month "12-05-2023" (DD-MM-YYYY)

My code in load script

reportdate:
load max([Bill Date]) as max_data
resident GroupOther;

LET vReportDate = date(num(AddMonths('max_data',-1,'reportdate')),'MM-DD-YYYY'); 

 Will this code work, if i need for Previous month "12-05-2023"? please help.

Thanks.

 

3 Replies
steeefan
Luminary
Luminary

No, this code will not work. max_data is not available as a field just so. You have to get it first from your table and then transform and format it:

 

LET vReportDate = peek('max_data', 0, 'reportdate');
LET vReportDate = Date(AddMonths($(vReportDate), -1), 'DD-MM-YYYY');

 

Ranjanac1
Contributor II
Contributor II
Author

Okay, so if i call this variable in my another code(below), which vReportDate it will take here or we can just changed it like that?

LET vReportDate = peek('max_data', 0, 'reportdate');
LET vReportDate1 = Date(AddMonths($(vReportDate), -1), 'DD-MM-YYYY');

LET vReportFilename = 'GroupSummary ' & '$(vReportDate1)' & '.xls';
//Export to excel is done with Post Reload trigger

steeefan
Luminary
Luminary

You can change your code as suggested.

However the second variable definition, LET vReportDate = Date(AddMonths($(vReportDate), -1), 'DD-MM-YYYY');, overwrites the first, i.e. the value of vReportDate will be the result of this expression. If you don't need the original date as a variable, you don't need to define vReportDate1.