Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
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?
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 :
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 :
cheers,
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,
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.
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 :
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 :
cheers,
Thank you for your help! The 2nd solution is the one we adopted.