Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
Announcements
Nov. 20th, Qlik Insider - Lakehouses: Driving the Future of Data & AI - PICK A SESSION
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Alt Function

Hi  Experts,

What is Alt Function ? where we have to use?

4 Replies
sunny_talwar

evan_kurowski
Specialist
Specialist

Alt function will attempt to iron out variances in number formatting when you can't predict a uniformity in a data source or multiple data sources.

For example, I used this significantly for a recent app in that was collating flat files from a variety of topics | locations | formats.

What the alt function does is say "try this date|time|number format.  Did it evaluate to a number?  Nope.  Ok, try the next format.  Did that evaluate to a number?  Nope.  Ok, try the next format."   And so on...

So let's say my log files turned out to store data in a variety of date formats.  What alt can help you test is a match for all different anticipated types:


LOAD
alt(
date#(DATE_FIELD,'MM/DD/YYYY'),
date#(DATE_FIELD,'MM-DD-YYYY'),
date#(DATE_FIELD,'YYYYMMDD'),
date#(DATE_FIELD,'YYYY-MM-DD')
)
AS [SO_HELP_ME_I_AM_SQUEEZING_A_DATE_OUT_OF_THIS_FIELD_IF_I_HAVE_TO_TEST_FOR_EVERY_PERMUTATION_EVER]

FROM LogFile.txt (txt);

Anonymous
Not applicable
Author

Hi,

Have a look:

Re: Alt function question

alt fun?

Hope it helps!!

Anonymous
Not applicable
Author

hi,

Alt(case1[ , case2 , case3 , ...] , else)
The alt function returns the first of the parameters that has a valid number representation. If no such match is found, the last parameter will be returned. Any number of parameters can be used.
Example:
alt( date#( dat , 'YYYY/MM/DD' ),
date#( dat , 'MM/DD/YYYY' ),
date#( dat , 'MM/DD/YY' ),
'No valid date' )

Will test if the field date contains a date according to any of the three specified date formats. If so, it will return the original string and a valid number representation of a date. If no match is found, the text 'No valid date' will be returned (without any valid number representation).


please check below post:


Re: Alt function

Which conditional functions do you use?