First you need to define a connection to the database in the library. Then in the script you need to establish a connection to the database using the connection you defined. After that you can load data from the database with an sql statement:
// step 1 - make a connection to the database
LIB CONNECT TO 'MyDataSource';
// step 2 - load the data from the database with an sql select statement
MIN( CASE when [Snapshot Date]='01/01/2015' THEN 1 else 0 end as [INDICATOR])
I think I did not define my problem well.
I am using an excel file for the data load currently.
And I have the data loaded in the app.
Now I face a situation wherein,
- I would like to create a calculated field. It need not be a SQL calculated field - its just something I knew. It could as well be a set expression if its possible.
- The acct and the calculated field( new acct indicator as explained in original question) can be a separate table in my data model. I do not want to disturb the original load script. I would ideally like to include this as a separate script.
If you're loading from an excel file the use LOAD instead of SELECT:
MIN( IF( [Snapshot Date]='01/01/2015' , 1 ,0)) as [INDICATOR]
'lib://MyFiles/MyExcelFile.xlsx' (ooxml, embedded labels, table is [Sheet 1]);
Depending on what your excel file contains you may need to use another comparison in the if statement. Perhaps this: If([Snapshot Date] = MakeDate(2015), 1, 0)
Ah, yes. You need to reference the source file correctly too. See the online help: http://help.qlik.com/en-US/sense/2.2/Subsystems/Hub/Content/Scripting/ScriptRegularStatements/Load.htm.
Perhaps it's easier if you use the Data Manager to add your excel data: Managing data in the app with the Data manager ‒ Qlik Sense. Then you can switch to the Date load editor and unlock the automatically generated section and modify the load statement to your needs.