Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

An interesting load question

I'm trying to load a file where the metrics are grouped by the first column, grouped as showen below

So for example, I sold Fords on 10/1-10/5. How can my QV Load regonized 10/2/-10/5 as belonging to Ford?

My result show look like the following

19 Replies
danielblank
Partner - Contributor III
Partner - Contributor III

Funny thing - it works with the Inline command.

I tried this with a sample code reading a sample excel document... That doesn´t work.

What is wrong with my code?

Regards,

Daniel

danielblank
Partner - Contributor III
Partner - Contributor III

Here is the sample Excel file

johnw
Champion III
Champion III

Since the peek() is reading from the table being built, you need to use peek('New') instead of peek('MainAccount') to get the right value. (Edit: Or just read in the expression as MainAccount instead of as New.)

danielblank
Partner - Contributor III
Partner - Contributor III

Thanx John - that solved it!

Thank you all for the prompt and great help!!!

Have a nice day,

Daniel

rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP


Tom Mackay wrote:The full syntax is with the single quotes, but as you've observed it seems to work without them as well.<div></div>


Leaving off the quotes only works in the simplest cases and I would recommend following the doc and always including the quotes. See

http://community.qlik.com/wikis/qlikview-wiki/forgetting-quotes-in-peek.aspx

for examples of problems caused by leaving off the quotes.

-Rob

johnw
Champion III
Champion III

Yeah, I realized I was playing with fire once I looked it up, and it did indeed have the single quotes. I'll definitely try to remember that in the future, and I should probably check a few applications to make sure I'm doing it right.

Not applicable
Author

You're preaching to the choir Rob. I was going to put a more verbose answer in along the same lines myself.

rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP


Tom Mackay wrote:You're preaching to the choir Rob


Everybody sing...

I wonder if we could get Qliktech to consider making this a fatal syntax error? It works without quotes sometimes and other times fails silently (returns a null) depending on where you are in the script.

I'm willing to submit a feature request along the lines of:
"Fail script with a syntax error if quotes are missing around peek() arguments".

Or is there a valid application for using an unquoted string? Am I missing something?

This would be a breaking change for apps that are running without the quotes.

-Rob

johnw
Champion III
Champion III

We're probably drifting further and further off topic, but I would want it to behave differently.

While I could easily be wrong, I suspect that the current syntax is a result of lazy coding rather than one of intentional design. I say this because I've done almost this exact same thing. A couple years ago, I added an exists() function to a custom compiler/interpreter at our company. The function is intended to tell you whether a field exists in the current data set or not. However, fields in a function are always evaluated before the function is executed on them. If we try to evaluate a field that does NOT exist, the interpreter gives a run time error. Under time pressure, it was much easier to just pass in the field name as a literal instead of as a field name, thus avoiding the run time error. Literals in this compiler are in double quotes, so my syntax was exists("field") instead of the desired exists(field).

So it would not surprise me if peek('field'), applymap('mapping table',field) and the like are simply the result of time pressures to put out new features rather than intentional decisions to deviate from the norm. Perhaps, as in my case, reading in the field or table names as literals was a kluge to avoid more drastic overhauls to the core code of the system.

So what I would want in a feature request isn't a syntax error, but rather consistencey - literals in single quotes, field names in double quotes or brackets (or neither if no white space), search strings in double quotes, and so on. I think it is poor form to require putting a field name or table name in single quotes for occasional functions. I don't like seeing what I consider violations of a standard. It detracts from ease of use and so on.

birubi
Contributor
Contributor

In your load script, add a field for the previous record value of the first column (when it is not the first record), then check the value of the first column, if blank then use the previous record value.