Smart Reports: tailoring your data to a context This worksheet describes how to use contexts and filters to create a report that is tailored for a specific user. By setting a context, you can tailor the text and values in a report. By setting a filter, you can limit the data. In this worksheet, you add a list of comments to the report created in the worksheet Smart Reports: creating multiple pdf reports using contexts. The comments will be filtered so that they only include comments for a specific restaurant. This is done by applying a filter based on context to the list analysis. The list analysis is added to the report RP1, along with a short description of the list. The description includes text based on the context, allowing you to tailor it for a recipient. You don’t want the description if there aren’t any comments, so the worksheet explains how to add the description conditionally. The N/A (not applicable) field holds the condition. This worksheet assumes that you have worked through the worksheets Understanding contexts and Smart Reports: creating multiple pdf reports using contexts. It uses the Crocodile survey supplied with Snap which is assumed to be in the condition it would be in after completing these two worksheets. If you do not have it, a survey like that is available here. Background As explained in the worksheet Understanding contexts, you can look at a subset of the data using a filter, or you can tag data of interest using a context. If you only want to look at the data relevant to a specific context, you must use a filter based on a context. For example, one could set up a context variable of colour to filter mice. If the context has been set to red, then you will have a subset of red mice to analyse. When the context is changed, the subset automatically changes as well. If no context has been applied, there will be no data to analyse. The Not Applicable (N/A) field Every report instruction has an N/A field. You can put a condition in the field saying when the instruction should not be used. Examples: you can check if an analysis contains data and make the instruction not applicable if there is no data you can use the N/A field to select between several different instructions, e.g, if you are producing a report for four different departments, you could set a condition based on context in the N/A field that excluded instructions that weren’t relevant to a department The power of combining contexts and filters The example report produced in this report uses a context of location. This allows you to generate separate reports with text and a benchmark analysis appropriate to the different locations. By adding further instructions to the report with filters based on the context, you can have analyses that only include the data specific to a given location. You can filter a whole report based on context, but in that case, you cannot use any analyses that require the whole dataset, such as a comparison between the different locations. Summary of steps Step 1: Adding the filter to your comments list Step 2: Adding a description for the comments to your report Step 3: Adding the comments list to your report Step 4: Setting when the text instruction will be used Step 5: Testing that the list is included correctly Step 1: Adding the filter to your comments list There is already a list analysis of comments in the Crocodile survey: AN7. Click on the Snap toolbar to open the Analyses window. Select AN7 and click on the analyses window toolbar to copy the list. It currently has a filter of Q8 ok applied. Add and Location=Location@context to filter the comments according to the current location (for each case, the value in Location must be the same as the current location set by the context). Select the Base/Labels tab. Clear the Reports Include options (Description, Notes and Title). Click [OK] to create the new list. It will be empty as no context has been applied (unless you have a global setting present in your survey). Select File|Context Values to open the Context Values dialog. Double click the global context value to open it. This allows you to set the context to a specific value. Set the Variable to Location and the Value to 1. This sets the current context to Bristol, UK. Click to save the context. Click on the analysis window toolbar to update the list. The comments for Bristol will appear. If you wish to check that the filter works for other contexts, open the global context value and set the value for Location to 2. Click on the Global Context toolbar to update the context. Click on the list analysis toolbar to update the list. The comments for London will appear. Click to save the list. Step 2: Adding a description for the comments to your report This section uses the report RP1 created in the worksheet Smart Reports: creating multiple pdf reports using contexts. Click on the Snap toolbar to open the reports window. Double click the report RP1 to open it. Click once on the last instruction in the list to select it. Click on the report dialog and select Information from the drop-down menu to add a new Information instruction after the last instruction. Enter the text “Comments received from customers at the ” in the large text area. Use the [Insert] button to open the Variable field... dialog. Select Location as the variable and set the Aspect as Context to insert the label of the current location. Finish the sentence by entering ” restaurant” in the text area. Click [OK] to save the instruction as instruction 5. Step 3: Adding the comments list to your report Click on the RP1 report dialog and select Execute from the drop-down menu to add a new Execute instruction. Click on the Execute dialog and select the AN18 (the comments list) from the list of analyses. Click [OK] to add the Execute instruction to the report. Step 4: Setting when the text instruction will be used It is possible that no comments will have been received for a restaurant. In this case, you do not want this text to appear. You can remove it by setting a N/A condition on the instruction. Double-click the information instruction (instruction 5) to open it. Type AN18 empty in the N/A field. This tests if there is currently any data in the comments list (analysis AN18). If there is not, the text instruction will not be used in the report. Click [OK] to save your changes. Step 5: Testing that the list is included correctly As shown earlier, if there is no context set, the comments list will be empty. Open your report if it is not open and clear the Context field (delete the CXloc). Select File|Context Values to open the Context Values dialog. Double click the global context value to open it. Delete the value of the Location variable to clear the context. Click to save the context. Change to the reports window. Select RP1 and click to run it. 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 entitled No reply. No comments will be visible and the instruction text will not be included. Set the context for the report to CXloc and run the report again. Four reports will be included, each one with the appropriate text and comments. Conclusion This worksheet has described how to use a filter based on a context to ensure the only data in the analysis is for the current context. It also explained what the N/A field is for and showed a simple example of use. If you want to see how to filter the data for a report based on a context, see the topic Creating a sub-report that contains data specific to a context. If you would like to see another example of including an instruction based on context, see Including an instruction based on context in a report. If you would like to see the reference material for report instructions, see the Report definition dialog and the topics it links to. If there is a topic you would like a worksheet on, email to snapideas@snapsurveys.com