Skip to main content
Announcements
NEW: Seamless Public Data Sharing with Qlik's New Anonymous Access Capability: TELL ME MORE!
cancel
Showing results for 
Search instead for 
Did you mean: 
johnca
Specialist
Specialist

Parse Years and Range of Years from Strings - Followup

Many thanks to Settu for accurately parsing out the years from the strings I provided in the initial thread. This is a followup to that and I admit I missed a few years to parse from. I did because I thought they were all similar and they are, but the results will be different. Each of them are associated to records with several other fields.

This is what I requested help on initially;

2018+

1996 and Older

1996 to Present

1997-2006

2008-Sept 2010

Oct 2010-Present

Parse Years and Range of Years from Strings

Here is new list of years and the expected outcomes are the same as those described in the initial thread (a year for each included value), linked to above. So, 1996 and Older would be each year from 1996 down to 1990. 2006 would be each year from 2006 down to 1990, etc.

 

2018+
1996 and Older
1996 to Present
1997-2006
1997-2013
2006 and Older
2007-2012
2007-2013
2007-2015
2007 and Older
2008-Sept 2010
2008 - 2010
2008 and Older
2009 and Older
2010 - Present
2011 - Present
2013-2017
2014-Present
2014 to Present
2016-Present
2016 - Present
2017-Present
Oct 2010-Present
1 Solution

Accepted Solutions
swuehl
MVP
MVP

Maybe like this

INPUT:

LOAD * INLINE [

String

2018+

1996 and Older

1996 to Present

1997-2006

1997-2013

2006 and Older

2007-2012

2007-2013

2007-2015

2007 and Older

2008-Sept 2010

2008 - 2010

2008 and Older

2009 and Older

2010 - Present

2011 - Present

2013-2017

2014-Present

2014 to Present

2016-Present

2016 - Present

2017-Present

Oct 2010-Present

];

MAP_DELIM:

MAPPING

LOAD In, '|' as Out INLINE [

In

-

and

to

+

];

MAP_LIMITS:

MAPPING

LOAD In, Evaluate(Out) as Out INLINE [

In, Out

+, Year(Today())

Present, Year(Today())

Older, 1990

];

TMP:

LOAD *,

keepchar(ApplyMap('MAP_LIMITS',trim(left)),'0123456789') as left_limits,

keepchar(ApplyMap('MAP_LIMITS',trim(right)),'0123456789') as right_limits;

LOAD *,

Subfield(Mapped_delim,'|',1) as left,

Subfield(Mapped_delim,'|',-1) as right;

LOAD String,

  MapSubString('MAP_DELIM',String) as Mapped_delim

Resident INPUT;

RESULT:

LOAD String, Rangemin(left_limits,right_limits)+iterno()-1 as Year

Resident TMP

While Rangemin(left_limits,right_limits)+iterno()-1 <= Rangemax(left_limits,right_limits);

String Year 19901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018
2018+ ----------------------------1
1996 and Older 1111111----------------------
1996 to Present ------11111111111111111111111
1997-2006 -------1111111111------------
1997-2013 -------11111111111111111-----
2006 and Older 11111111111111111------------
2007-2012 -----------------111111------
2007-2013 -----------------1111111-----
2007-2015 -----------------111111111---
2007 and Older 111111111111111111-----------
2008-Sept 2010 ------------------111--------
2008 - 2010 ------------------111--------
2008 and Older 1111111111111111111----------
2009 and Older 11111111111111111111---------
2010 - Present --------------------111111111
2011 - Present ---------------------11111111
2013-2017 -----------------------11111-
2014-Present ------------------------11111
2014 to Present ------------------------11111
2016-Present --------------------------111
2016 - Present --------------------------111
2017-Present ---------------------------11
Oct 2010-Present --------------------111111111

View solution in original post

3 Replies
johnca
Specialist
Specialist
Author

I tried adding another if statement but it kept bombing on me so I looked at the data again. If the differences are only a hyphen vs a space-hyphen-space I was able to get the owner to change his file such that the spaces were removed in the Year to Year values. So, '2008 - 2010' became '2008-2010', etc. and now it works.

I will continue with a more robust If Then ElseIf for the original values but one of the things a developer does is cleanse data too.

Again, thanks to Settu for providing the original fix.

swuehl
MVP
MVP

Maybe like this

INPUT:

LOAD * INLINE [

String

2018+

1996 and Older

1996 to Present

1997-2006

1997-2013

2006 and Older

2007-2012

2007-2013

2007-2015

2007 and Older

2008-Sept 2010

2008 - 2010

2008 and Older

2009 and Older

2010 - Present

2011 - Present

2013-2017

2014-Present

2014 to Present

2016-Present

2016 - Present

2017-Present

Oct 2010-Present

];

MAP_DELIM:

MAPPING

LOAD In, '|' as Out INLINE [

In

-

and

to

+

];

MAP_LIMITS:

MAPPING

LOAD In, Evaluate(Out) as Out INLINE [

In, Out

+, Year(Today())

Present, Year(Today())

Older, 1990

];

TMP:

LOAD *,

keepchar(ApplyMap('MAP_LIMITS',trim(left)),'0123456789') as left_limits,

keepchar(ApplyMap('MAP_LIMITS',trim(right)),'0123456789') as right_limits;

LOAD *,

Subfield(Mapped_delim,'|',1) as left,

Subfield(Mapped_delim,'|',-1) as right;

LOAD String,

  MapSubString('MAP_DELIM',String) as Mapped_delim

Resident INPUT;

RESULT:

LOAD String, Rangemin(left_limits,right_limits)+iterno()-1 as Year

Resident TMP

While Rangemin(left_limits,right_limits)+iterno()-1 <= Rangemax(left_limits,right_limits);

String Year 19901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018
2018+ ----------------------------1
1996 and Older 1111111----------------------
1996 to Present ------11111111111111111111111
1997-2006 -------1111111111------------
1997-2013 -------11111111111111111-----
2006 and Older 11111111111111111------------
2007-2012 -----------------111111------
2007-2013 -----------------1111111-----
2007-2015 -----------------111111111---
2007 and Older 111111111111111111-----------
2008-Sept 2010 ------------------111--------
2008 - 2010 ------------------111--------
2008 and Older 1111111111111111111----------
2009 and Older 11111111111111111111---------
2010 - Present --------------------111111111
2011 - Present ---------------------11111111
2013-2017 -----------------------11111-
2014-Present ------------------------11111
2014 to Present ------------------------11111
2016-Present --------------------------111
2016 - Present --------------------------111
2017-Present ---------------------------11
Oct 2010-Present --------------------111111111
johnca
Specialist
Specialist
Author

Wow, Stephan, this too works, and actually a bit better and easier to maintain I think. I was able to apply this one to the existing document as-is and didn't need to clean an data. 🙂

Many thanks for the input...I will probably use this one in the final dashboard.

V/r,

John