Friday, June 11, 2010

User Option done as a Field Selection



I’ve prepared a number of reports where the person who opens the report must make a choice about something that affects the report functionality or something that affects the way the report objects look. There are several ways to approach that issue when you design a report. Here’s an example from a recent report I designed.

The report had a chart in it that could show data by various units of measure or “UOM”. The unit of measure could be Cases or Eaches or Dollars and the chart object expressions would handle the conversions. We decided that we’d like the user to be able to change the UOM selection in a Multi-box on the tab so that the user could make all of her selections in one place. UOM doesn’t actually appear in the data being loaded so I had to put a little in-line table into the loadscript that defined the three values. It looked like this:
UOM_SELECTION:
Load * Inline
[UOM
Cases
Eaches
Dollars];


Then I loaded a new set of data into the report. Now, I could add the UOM field to the multi-box and the user could treat it the same as any other selection.

The Multi-box object has a feature on the Presentation tab that works well with this kind of field. If you first select one of the values of the field you can open up the Multi-box Properties dialog and choose the Presentation tab and click the Always One Selected Value check box (If you don’t first select a single value then the checkbox will be grayed out). This helps the user avoid making a mistake with the UOM selection – the user is prevented from clearing the selection in that field and prevented from selecting more than one value. Since the UOM field selection is only for one value, an expression in the chart can refer to it simply by name; for example, the expression might say If(UOM='Dollars',sum(sales)*unit_cost)

I made two other changes to the chart just to make sure that there would be no confusion about the UOM value:
I opened the Chart Properties dialog for the chart selected the General tab and put this expression into the Calculation Condition:
=if(count(distinct UOM)=1, 1, 0)

That will check to make sure that one and only one value of UOM is selected otherwise the chart will show an error message. Then I modified the error message text from the default value of “Calculation condition unfulfilled” to a more useful message that said “Please select a single UOM value to see this chart”.
★ ★ ★

1 comment:

Dan H said...

Great post Tim. Love reading your short tutorials. I've been posting them up to Twitter as well - hope you don't mind! You can check the #QlikView hashtag. Cheers.