Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

Announcements
QlikWorld 2020: Join us May 11 - 14, 2020 in Phoenix, AZ. Register early and save $400. Learn More
stevetucker
New Contributor

Does Qlik have the ability to create functions similar to TSQL functions?

Sorry if this has been asked before but does Qlik enable you build functions?
In SQL Server we would have build a procedure or function to achieved complex row by row analysis, is there something similar in Qlik?

Thanks for any help.

Steve

8 Replies
MVP & Luminary
MVP & Luminary

Re: Does Qlik have the ability to create functions similar to TSQL functions?

Yes, there is with interrecord-functions like: Peek() or Previous() ?

- Marcus

sasiparupudi1
Honored Contributor III

Re: Does Qlik have the ability to create functions similar to TSQL functions?

Qlik will only allow you to write user defined procedures in the syntax similar  to that of VB. No user defined functions possible.

ex:

sub myProc

your logic

End Sub

MVP & Luminary
MVP & Luminary

Re: Does Qlik have the ability to create functions similar to TSQL functions?

User defined functions could be implemented by variables with parameters:

Variable That Acts Like a User-Defined Function.

Dynamic Field Expressions with Variables

Variables with Parameters

- Marcus

sasiparupudi1
Honored Contributor III

Re: Does Qlik have the ability to create functions similar to TSQL functions?

I agree but they are not quite the same as a procedure/function where one can write some complex logic

Best

MVP & Luminary
MVP & Luminary

Re: Does Qlik have the ability to create functions similar to TSQL functions?

Surely some things might require more efforts but others will be even easier as in (T)SQL so that I think that everything what could be done in (T)SQL could be done in Qlik too, but in different ways. Further I think that adapting the logics to the way Qlik works is better as trying to keep the SQL logic at least if one want to use the advantages of Qlik.

- Marcus

stevetucker
New Contributor

Re: Does Qlik have the ability to create functions similar to TSQL functions?

Thanks Guys

I have also been looping at resident tables and loops.

Would it make sense to do something like the following?

1 Load up a distinct list of custmers from a resident table

2 Loop through each customer

3 Load up a temporary table of transaction records for the specific customer in the loop

4 Copy the customer record and processing to another table

5 Drop the temporary table

6 Loop to the next customer

Essentially being left with a copy of the data with the processing for each customer?

There could be a better way and I am limiting myself to relational DB thinking... but basically using the resident tables as curors and loops in TSQL

MVP & Luminary
MVP & Luminary

Re: Does Qlik have the ability to create functions similar to TSQL functions?

1/2 don't need a resident load because a loop over the fieldvalues would be enough like here:

Re: For each - get a second value associated

For 3 could the for each variable be used as filter within the where-clause.

By 4 I don't understand the meaning what should happens.

5 just add: drop table YourTableName;

6 see to 1/2

But what is the aim to create a single table for each customer - it don't seemed to be a store as file so it's related to 4?

- Marcus

Partner
Partner

Re: Does Qlik have the ability to create functions similar to TSQL functions?

In Qlik, you can create functions and also sub routines.

For sub routines , you would use Sub Routine_name() .... End Sub;

For Functions, You would Function Function_name() ..... End Sub;