LAE

Welcome to the LAE community!  Please feel free to start a discussion in the discussion tab or join in a conversation.

Discussions

Members

Resources

Events

 View Only
  • 1.  Rename Columns depend upon value on another column

    Employee
    Posted 07-14-2016 09:37

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: Jagdev

    Hi Experts,

    I need your help on setting up loop condition on my data. What I am looking for is changing list of column names depends upon value of another column. When I am trying to use if condition it is throwing an error. The value of column will change, but the column name will be same. Am I doing something wrong with the syntax

    if 'Client Name' == "ABC" then
    {
    rename LOB as LO
    }
    if 'Client NAme' == "DEF" then
    {
    Rename LOB as L
    }


  • 2.  RE: Rename Columns depend upon value on another column

    Employee
    Posted 07-14-2016 12:48

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: stonysmith

    You can't rename columns that way. If you think about it, every record must have the SAME column names.
    So, if some record has LO and not L, what value should go in the other column?

    The proper way to do this is:
    emit *
    LO=str(null)
    L = str(null)
    if 'Client Name' == "ABC" then LO=LOB
    if 'Client NAme' == "DEF" then L=LOB
    emit L,LO


  • 3.  RE: Rename Columns depend upon value on another column

    Employee
    Posted 07-20-2016 06:58

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: Jagdev

    Hi Stony,
    Thanks for the code.
    But I am stuck with my real requirement. The logic behind creating the code is to change few columns from different files. The fixed column Client Name is fixed in all the data sets. I mistakenly spelled it wrong above. Also the change column name will vary in each and every sheet. I thing in my above example I used LO=LOB and L=LOB, but that is not the case. The actual column name in the data set would be different. It is not mandatory that the list of columns would be available in second loop or in further loops.

    Let me brief you on this. There is a fixed column name “Client Name” and the name within this column will keep on changing. Depend upon the value in this column. I have to change the list of column names and the changed column name should reflect in the output of the node. So accordingly depend upon my column value will change the list of column and want the output as a changed value.
    Please let me know if I am still unclear.
    Regards,
    Jagdev


  • 4.  RE: Rename Columns depend upon value on another column

    Employee
    Posted 07-20-2016 08:03

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: Jagdev

    Logic should be something like this. Help me to accomplish this

    emit *
    if 'Client Name' == "ABC" then
    Code='Cause'
    Code_Group = 'Case Group'
    Part_ID='Part of ID'
    Department = 'Location'
    emit Code,Code_Group,Part_ID,Department
    else if 'Client Name' == "DEF" then
    LO='LOB'
    L='LOB Cause'
    emit LO,L
    else if 'Client Name' == "GHI" then
    AB='ABCD'
    CD='EFGH
    emit AB,CD


  • 5.  RE: Rename Columns depend upon value on another column

    Employee
    Posted 07-20-2016 11:23

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: stonysmith

    You can't EMIT based on an IF. Unless you are writing to separate outputs, all the columns must (will) exist on every output record.


  • 6.  RE: Rename Columns depend upon value on another column

    Employee
    Posted 07-22-2016 02:28

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: awilliams1024

    As Stony says, within a single data set all records must have the same fields (even if they contain NULL values in some fields).

    You can separate a data set into multiple subsets and then append additional fields to each subset. However, if you then want to recombine these subsets into a single dataset then the combined dataset would need to be a union of all the fields across all the subsets, with the 'missing' fields in each record given a value (e.g. NULL).

    The attached dataflow shows some options. The top section of the dataflow illustrates how the input dataset can be split into the subsets and then additional fields appended to each subset, as required. If you want to combine the subsets, the Cat node can be configured to generate the union of all fields - which will insert NULL values into the 'missing' fields in each record. This example is designed for clarity of the logic rather than optimized performance as it requires multiple stages to process the data.

    The second example in the middle of the dataflow shows how this processing could be achieved in a single stage - at the expense of additional complexity within the Filter node.

    However, I think that both of these approaches are relatively 'rigid' solutions in that the Filter nodes need to be configured with separate output pins to reflect each of the values in the reference field ('client value'). You may want to consider using another approach to create the combined data set such as using a Lookup (or a Xref) with some reference data to drive the enrichment of the input dataset (see the example at the bottom of the dataflow). The combined data has been sorted for clarity of the example in this case.


    Add_Fields_based_on_Field_Values.brg

    Regards,
    Adrian


  • 7.  RE: Rename Columns depend upon value on another column

    Employee
    Posted 07-26-2016 06:27

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: Jagdev

    Hi Adrian and Stony,

    Thanks for your guidance on this thread. Really informative. I will try to incorporate the logic in my real time data.

    Regards,
    Jagdev