Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
firmographs
Partner - Contributor III
Partner - Contributor III

creating a new dimension in the load script

In the load script, we'd like to create a new dimension based on the result of an expression.  This works in the expression editor, but I'm not sure we can do it in the load script.  

We want a dimension flag, based on there being a value for 'A'.

The logic would be for a site:

if(count(A)>0,'Has A','Does not have A') as "Flag, Has A"

So if dimension A is null for a site, the value of "Flag, Has A" would be 'Does not have Flag A'.  

Is this possible in the load script?

 

Labels (2)
1 Solution

Accepted Solutions
Taoufiq_Zarra

For this case there are several possibilities to do it

1-you can simply add the condition in your LOAD instruction

LOAD if(len(Vendor)>0,'Has Vendor','No Vendor') as VendorFlag,* INLINE [
    Site, Vendor
    Site 1, Vendor 1
    Site 2, Vendor 2
    Site 3, Vendor 1
    Site 3, Vendor 2
    Site 3, Vendor 4
    Site 5
    Site 7, Vendor 1
    Site 7, Vendor 4
    Site 10, Vendor 2
    Site 10, Vendor 3
    Site 11
];

 

output :

Capture.PNG

otherwise if you absolutely want to use the count(), you can for example use this script :

INPUTS:

LOAD * INLINE [
    Site, Vendor
    Site 1, Vendor 1
    Site 2, Vendor 2
    Site 3, Vendor 1
    Site 3, Vendor 2
    Site 3, Vendor 4
    Site 5
    Site 7, Vendor 1
    Site 7, Vendor 4
    Site 10, Vendor 2
    Site 10, Vendor 3
    Site 11
];



RESULTS:

LOAD

Site,

if(count(if(len(Vendor)>0, Vendor))>0 ,'Has Vendor','No Vendor') as VendorFlag

Resident INPUTS

Group By Site;

DROP Table INPUTS;

 

results :

Capture.PNG

cheers,

Regards,
Taoufiq ZARRA

"Please LIKE posts and "Accept as Solution" if the provided solution is helpful "

(you can mark up to 3 "solutions") 😉

View solution in original post

4 Replies
Taoufiq_Zarra

Hi,

yes it is possible by using Group By and load from Resident.

give more details of your script to help you efficiently (with a sample data is more efficient)

 

Cheers,

Regards,
Taoufiq ZARRA

"Please LIKE posts and "Accept as Solution" if the provided solution is helpful "

(you can mark up to 3 "solutions") 😉
firmographs
Partner - Contributor III
Partner - Contributor III
Author

This is my draft script, which I know is not right yet, but it shows the logic we are after:

if(count(Vendor)>0,'Has Vendor,'No Vendor') as "Vendor Flag"

 

Sample data is attached.  

 

Taoufiq_Zarra

For this case there are several possibilities to do it

1-you can simply add the condition in your LOAD instruction

LOAD if(len(Vendor)>0,'Has Vendor','No Vendor') as VendorFlag,* INLINE [
    Site, Vendor
    Site 1, Vendor 1
    Site 2, Vendor 2
    Site 3, Vendor 1
    Site 3, Vendor 2
    Site 3, Vendor 4
    Site 5
    Site 7, Vendor 1
    Site 7, Vendor 4
    Site 10, Vendor 2
    Site 10, Vendor 3
    Site 11
];

 

output :

Capture.PNG

otherwise if you absolutely want to use the count(), you can for example use this script :

INPUTS:

LOAD * INLINE [
    Site, Vendor
    Site 1, Vendor 1
    Site 2, Vendor 2
    Site 3, Vendor 1
    Site 3, Vendor 2
    Site 3, Vendor 4
    Site 5
    Site 7, Vendor 1
    Site 7, Vendor 4
    Site 10, Vendor 2
    Site 10, Vendor 3
    Site 11
];



RESULTS:

LOAD

Site,

if(count(if(len(Vendor)>0, Vendor))>0 ,'Has Vendor','No Vendor') as VendorFlag

Resident INPUTS

Group By Site;

DROP Table INPUTS;

 

results :

Capture.PNG

cheers,

Regards,
Taoufiq ZARRA

"Please LIKE posts and "Accept as Solution" if the provided solution is helpful "

(you can mark up to 3 "solutions") 😉
firmographs
Partner - Contributor III
Partner - Contributor III
Author

Thank you for your help!  The 2nd solution is the one we adopted.