Skip to main content
Announcements
See what Drew Clarke has to say about the Qlik Talend Cloud launch! READ THE BLOG
cancel
Showing results for 
Search instead for 
Did you mean: 
jaygarcia
Contributor III
Contributor III

Preparing Expressions To Load based on Condition field on a CSV

Hi guys,

I want to load some fields with dynamic expressions set up through a cvs file based on Condition that filters the Expression field value.

The Excel sample file looks like this:

  

ExpressionFieldAliasCondition
IF(TransactionTypeID=1, UnitsX)SumOfUnitsXvLoadSalesType1
RevenueX*USDxRateRevenueX_USDvLoadSalesType1 AND vLoadPriceType1
RevenuesY*EURxRateRevenueY_EURvLoadSalesType2 AND vLoadPriceType1

The "Condition" field values are variables in the app/doc that depend on other Config settings from a different csv file, which could be either 1 or 0. These variables will be used to filter the rows of Expressions needed in my App. For example, my specific App could not vLoadSalesType2=0 and row 3 (Expression value) should not be loaded.

My idea is that in the LOAD statement I could convert the Expression with ' as ' & FieldAlias as a Fieldname and then load a CONCAT of Fieldname in order to create a variable with a list of fields to be finally loaded in a final LOAD from the actual Data table.

My attempts have been unsuccessful so far and would highly appreciate some light

Hope it makes sense.

Thanks!

Jay

1 Reply
jaygarcia
Contributor III
Contributor III
Author

I think I found the solution:

ControlFile:

LOAD

     rowno() as Row_Number,

     Expression,

    FieldAlias,

    Condition

FROM ControlFile.csv (txt, codepage is 28591, embedded labels, delimiter is ',', msq);


LET vRowsNumber = fieldvaluecount('FieldAlias');

FOR i = 1 to vRowsNumber

     Let vCondition = Peek('Condition',$(i)-1,'ControlFile');

     IF $(vCondition) then

          Temp: // CONCATENATE assumed next load

          LOAD

               Expression & ' as ' & FieldAlias  as ExpressionField

          Resident ControlFile

          Where Row_Number=$(i);

     ENDIF

NEXT i


Drop table ControlFile;





So now I have my ExpressionField field that I will load with CONCAT() to be used to create a variable for my final DATA load


Jay