Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

Announcements

Breathe easy -- you now have more time to plan your next steps with Qlik!
QlikView 11.2 Extended Support is now valid through December 31, 2020. Click here for more information.

jblomqvist
Not applicable

How can I make this Rand() script work? Trying to assign a Sales Person based on a random ID?

Hi all,

I have the following piece of script:

Emp:

LOAD Floor(SalesID) as SalesID, Name INLINE [

    SalesID, Name

    1, Julie

    2, John

    3, David

    4, David R

    5, Teresa,

    0, Michael

];

Data:

LOAD

ApplyMap('Emp', RandNum,'Missing') as SalesPerson,

*;

LOAD

     Floor(Rand() * 5) as RandNum,

     <other data>

FROM datafile.xls;

The output is blank for SalesPerson column:

Any idea how to fix this?

The point is to assign a random sales person based on the RandNum field.

1 Solution

Accepted Solutions
kush141087
Not applicable

Re: How can I make this Rand() script work? Trying to assign a Sales Person based on a random ID?

Mapping key word missing

Emp:

mapping LOAD Floor(SalesID) as SalesID, Name INLINE [

    SalesID, Name

    1, Julie

    2, John

    3, David

    4, David R

    5, Teresa,

    0, Michael

];

4 Replies
kush141087
Not applicable

Re: How can I make this Rand() script work? Trying to assign a Sales Person based on a random ID?

Mapping key word missing

Emp:

mapping LOAD Floor(SalesID) as SalesID, Name INLINE [

    SalesID, Name

    1, Julie

    2, John

    3, David

    4, David R

    5, Teresa,

    0, Michael

];

sunny_talwar
Not applicable

Re: How can I make this Rand() script work? Trying to assign a Sales Person based on a random ID?

Did you miss the Mapping keyword?

Emp:

MAPPING

LOAD Floor(SalesID) as SalesID, Name INLINE [

    SalesID, Name

    1, Julie

    2, John

    3, David

    4, David R

    5, Teresa,

    0, Michael

];

jblomqvist
Not applicable

Re: How can I make this Rand() script work? Trying to assign a Sales Person based on a random ID?

Of course, such a silly mistake thank you

swuehl
Not applicable

Re: How can I make this Rand() script work? Trying to assign a Sales Person based on a random ID?

And maybe use

   Floor(Rand() * 6) as RandNum,


so that Teresa gets a chance to get picked, too.