Smart Reports: creating multiple pdf reports using contexts This worksheet describes how to set up a Smart Report so it creates multiple pdf reports with Snap dynamically selecting the data depending on the context. It explains how to set up the survey in Snap so that it will produce all the reports that are needed, and then tells you how to set up the report instructions so that each report will be sent to a different pdf file. This worksheet uses the sample Crocodile survey supplied with Snap. The survey evaluates a restaurant chain with four branches (two in the UK and two in the USA). The worksheet describes how to use the location in a context data set, allowing you to produce separate reports for each location. The example starts with the report created in the worksheet Understanding contexts and shows you how to set it up so that a separate pdf file is produced for each restaurant manager, ready to be sent to them or printed out. The worksheet assumes: you are have worked through the worksheets: Creating a Smart Report which includes automatic text and Understanding contexts you have a pdf printer driver available Background The worksheet Understanding contexts explained how to change what data was used depending on the information stored in a context variable and showed you how to set the current context by using the global data set. The global data set allows you to set a context manually. You can also tell Snap to automatically create a report or an analysis multiple times by using a context data set. This worksheet shows you how to set up a simple version of a context data set. It contains a single variable (Location) and tells Snap to use the received responses to work out how many reports or analyses to create. Snap looks at the raw data file (the responses received) and sets the context in turn to every value that has been received for the specified variable. For the Crocodile survey, if you placed the Location variable in a context data set, this would mean that if you had received responses from New York, Boston, London, but none from Bristol, reports would only be generated for New York, Boston and London, as there would be no responses in the raw data file with a value of Bristol, UK. Creating separate files with a page layout instruction When you create a report in Snap it is normally sent directly to the printer driver as a single file. If you wish to create separate files for the different contexts, you must set it up so it starts each version of the report on a new page, and places it in a new file. The breaking up of the report is done using a Page Layout instruction. This tells Snap when to start a new page and when to start a new file. Summary of steps Add the page layout instruction to your report Set up the context data set to create all the reports you need Run the report to generate the separate pdf files Creating a context data set using the location variable Snap can run reports for all locations if you create a Context data set. Select File|Context to open the Context Values dialog. Click to create a new context. The Context Data Set dialog appears. By default it will have a name of CX1. Change this to CXloc. The CX will identify it as a context variable, and the loc tells you it is the location. Set the Type to Raw data. This uses data in the survey (the raw data file). Set the Label to Restaurant location so you know what the data set it for. Type Location in the Variables field. This tells Snap that the contexts are all the values in Location. (This assumes that you have changed the name of variable Q0 in the Crocodile file to Location as described in the worksheet Understanding contexts. If you have not, do so or use Q0.) Click to save the context data set. You can now use it to automatically generate multiple reports. Loop round all the context reports Open your report if it is not open and enter CXloc as the Context. Click on the report dialog and select Page Layout from the drop-down menu. Select Start New Page. This ensures that each time the report is run it starts on a new page. If the Page Layout instruction is not the first instruction in the report, select it in the window and drag it to the top of the list of instructions. Click to run the report. The Report Execution dialog opens. Click [Printer] to confirm that you are printing to the pdf printer driver. Click [OK] to close the Print Setup dialog. Click [OK] on the Report Execution dialog. It will produce a single report file with four versions of the content, one for each possible value of the variable listed in CXloc. Each one will start on a new page. Setting up the report to create separate files You need to modify the Page Layout instruction at the start of your report to tell Snap to save the different reports to separate files. Double-click the Page Layout instruction to open it. Select Restart Page numbers to ensure that each document starts on page 1. Select Start New Document. This places the report in a new file, (so each time it creates the report for the different context, it will start a new file). Click [Insert] and select Variable field from the list. Select Location as the Variable and Context as the Aspect. This will use the label of the Location for the current context as the filename, so the report for Boston will be given a filename of Boston, MA.pdf. Click [OK] to close the New Variable field dialog. . Click [OK] to save your instruction. Click to run the report, then click [OK] on the Report Execution dialog. Depending on the pdf driver that you are using, and the way it has been set up, it will either automatically save or ask you to save the files. The picture below shows the four files in PDFCreator. Once the files have been saved, you can check that they are as you expect. Snap should have created a report for each value of Location, and used the appropriate label as the filename. Conclusion This worksheet has described how to automatically change the context to create multiple versions of the report from the same data. It has also explained how to use a Page Layout instruction to create separate files, named according to the context, to store each report. If you would like to see other examples of using contexts see Using contexts to provide personalised reports and questionnaires. If you would like more examples of how to lay out a report, see the list of topics at Laying out your reports. For reference information about the page layout instruction, see the topic: Report instruction dialog: Page Layout: Page breaks tab. If there is a topic you would like a worksheet on, email to snapideas@snapsurveys.com