set chart=ActiveDocument.GetSheetObject("CH01")
Friday, December 16, 2011
Count of Rows in a Chart
set chart=ActiveDocument.GetSheetObject("CH01")
Friday, November 18, 2011
Select Top 4 Values On Open
I was working on a document that contained a lot of data and the performance when the document was opened or when the user moved from tab to tab was a little slow. On my own laptop when I save documents like that I usually make a selection of a small amount of data so that later when I open the document again it will open quickly. I wanted to do something like that for the users -- some kind of selection that would happen automatically when the document is opened, but it had to be a selection of data that would be useful and easy for the users to understand.
The data in the document was organized by a date field named POSTDATE so I decided that I would like the document to automatically select the most recent four POSTDATE values when it was opened. Most users look in the document for the most recent data and anyone who wanted to review older data could easily add older dates to the selection through the multibox.
The method I used is to create a trigger that would fire when the document is opened. The trigger would do a Pareto Select. Now, I'm not saying that this is the best way to accomplish the selection and it certainly is not the only way, but it was easy and didn't involve writing macro code.
Pareto Select is used to select a percentage of values in a field based on ranking of a value or expression. It is commonly used select things like the top 20% best selling products. In this case I wanted to use it to select not a fixed percentage but the four most recent POSTDATE date values. This is what I did:
From the menu choose Settings->Document Properties and choose the Triggers tab.
In the document event triggers click the Add Action button for the OnOpen event.
Click Add Action and in the Add Action dialog choose Action Type=Selection and Action=Pareto Select then click OK.
In the Actions dialog type POSTDATE into both the Field and Selection boxes. POSTDATE is not only the field I want to select but also the expression value I want ranked.
Then, in the Percentage box enter =(4/COUNT(DISTINCT POSTDATE))*100
And click OK. Save the document and the next time it is opened it will automatically select the four most recent POSTDATE values.
A similar method could be used to do automatic selection of any number of top values of any field. Pareto Select does its selection based on the current Possible values. If you wanted to ignore the current selection and select a percentage of all values then you should add an extra action to the trigger to clear the field before making the Pareto Selection.
Testing trigger actions is most easily done by defining the same actions for a button and then you can test the action by clicking the button. When you're done testing, remove the button and make sure the actions are associated with the proper event.
= = = = = = = = = = = = = = = = = = = = = = = = = =Author's Note 6Dec2011:
This method didn't work the way I wanted when the document already included selections on the POSTDATE field. I couldn't find any good way to deal with that using the available trigger actions. I eventually replaced the Pareto Select action with a macro action that selects the four most recent POSTDATE values. The macro code looks like this:
sub Top_4_POSTDATE
set fd=ActiveDocument.GetField("POSTDATE")
fd.Clear
fd.TopSelect "=if(aggr({1} rank(POSTDATE),POSTDATE)<=4,POSTDATE)",4
set fd=nothing
end sub
* * *
Saturday, November 12, 2011
Replace IF in Expression with Set Analysis
Friday, November 4, 2011
Increasing Likelyhood of Duplicate Values While Loading Data
- Truncating text data - keeping only the first ten characters, for example.
- Trimming text data to remove any leading or trailing blanks.
- Converting to all capital letters.
- Converting non-abbreviated words to standard abbreviations, like state abbreviations in address data.
- Removing the time stamp portion from date data
- Converting date data to beginning-of-week or beginning of month dates.
- Converting date data to month abbreviations if that is the level of data used in the document charts.
Sunday, October 23, 2011
Using Oracle Configured for Different Countries
Friday, August 19, 2011
Looking Inside a Bookmark Without Opening It
I had never thought about how you might do that. It is not difficult to list out the possible values for a single field based on a bookmark whether the bookmark has been opened or not. For example, for a bookmark named Feb_Sales and a field named ITEM you can put a text expression like this into a text object or chart title:
=concat({Feb_Sales} distinct ITEM, ', ')
That will give you a list of the ITEM values separated by commas. Note that it is a list of Possible values, it will only be the Selected values if the bookmark includes a selection on that particular field.
This technique can be used to give the user a peek into the selected or possible field values in the bookmarks; perhaps helping a user decide which bookmark should be used.
Friday, July 29, 2011
A Chart Expression That Works Differently for Totals Row
if(IsNull(RowNo()),
/* do the totals row calculation */ ,
/* else, do the regular calculation */)
if(IsNull(RowNo()),yellow())
Important note: If you use the RowNo() function in your column expression you will not be able to re-sort the chart by double-clicking on a column title. If that is a problem for your application then use if(Dimensionality()=0,... as a substitute.
Friday, July 15, 2011
Duplicate Rows in a QlikView Table
To help identify the problem, add a row number field to each row in the QlikView table. That will give you at least one field that is unique on each of the duplicate rows. You can do this without reloading the entire document. Here's an example-- First, save a backup copy of the report that you are working on. Assume that the table to which you want to add a row number is named REDFLIGHTS. Add these rows to the top of your loadscript:
REDFLIGHTS_X:
Add Load RowNo() as REDFLIGHTS_RowNo, * Resident REDFLIGHTS;
Drop Table REDFLIGHTS;
Rename Table REDFLIGHTS_X to REDFLIGHTS;
Exit Script;
Then, from the menu, select File->Partial Reload This will run the five lines you added to your loadscript and it will build a new table inside the document that is identical to your original table but with a rownumber field, REDFLIGHTS_RowNo, added to the table. Now, in a tablebox that includes the rownumber field or in a chart using the key fields as dimensions and using a count(REDFLIGHTS_RowNo) expression you will be able to identify the duplicate rows in the table. At that point you will have to figure out how to eliminate or handle the duplicate rows when data is loaded. Remember to remove the five lines from the top of your loadscript before you next try to reload data.
Sunday, July 3, 2011
Loading Multiple Files With Varying Fields
for each sfile in filelist (e:\sales_history\QVD_SALES_MONTH*.qvd)
If filectr=0 then
SALES_TABLE:
Load * from $(sfile) (qvd);
Else
SALES_TABLE:
Concatenate Load * from $(sfile) (qvd);
EndIf
Let filectr=$(filectr)+1;
next sfile
Monday, June 27, 2011
Export All Data From All QV Tables to Text Files
Last week one of our clients asked me to provide a method that they could use to export all of the data from within a QlikView document. They had hundreds of archived documents and they wanted to be able to export the data and use it in another application.
2. Copy the QlikView .qvw document file into your folder. This will make sure you don't accidently update the original document.
3. Double-click on the .qvw file to start up QlikView.
4. From the menu, select File->Edit Script. This opens up the Loadscript Edit Window.
5. At the very top of the loadscript, before the first line, copy and paste in these lines:
/* Export all QlikView tables to tab-delimited files */
if IsPartialReload() then
for ix= 0 to 100
let tn=trim(tablename($(ix)));
if len('$(tn)')<1 then
exit script;
end if
Store "$(tn)" into "EXPORTED_QV_$(tn).TXT" (txt, delimiter is "\t");
next ix
end if
exit script;
//
6. Close the Loadscript Edit Window by clicking the OK button in the lower right corner of the window.
7. From the menu, select File->Partial Reload
If everything works correctly, each of the QlikView tables will be written out as tab-delimited text files into the folder. For example, if the QlikView document contains a QlikView table named HISTCUST then it would write out a text file named, EXPORTED_QV_HISTCUST.txt. The first record will contain the field names.
Note the syntax for specifying the delimiter character. If your Store command simply includes (txt) without specifying the delimiter you will get comma-delimited text files. Use the file specification, (qvd), to get QlikView QVD files.
Sunday, April 3, 2011
Variable That Acts Like a User-Defined Function
* * *
Friday, January 14, 2011
Loading Scientific or E-Notation
That IF statement in the loadscript converted any e-notation values in the data into numbers and for regular numeric values loaded them as usual.
Later in the day, I needed to load the same data into an Oracle table using Sql Loader. Interesting that the idea is the same but the syntax is different. This is what the entry in the SqlLdr control file looked like: