Transforming an array of custom fields

I have a dataset currently flowing in from MongoDB which is essentially populated based on custom fields that are optionally set within the source. Each element in the array has the name and value of the custom field (ie. customField<0-N>_fieldName and customField<0-N>_fieldValue). The issue is that it's not always the same column for the same field as
we use this as an array of custom fields, and not as specific fields for specific custom fields.

To make it simpler for a user to find all custom fields with certain key, I am trying to add columns in the ETL to pull in values for a specific custom field, if it exists. As an example, add a column for Member_Info_Verified. This follows a conditional value to check customField<0-N>_fieldName == 'Member_Info_Verified'  and if so, set the value tocustomField<0-N>_fieldValue, otherwise leave empty.

Attaching a few screenshots of the various types of rows I see for Name/Value combinations. Type can be ignored. Open to any sort of advice whether it be using a combination of formula tiles or running a Python script.

Best Answer

  • ST_Superman
    ST_Superman Domo Employee
    Answer ✓

    @tmerchant

    I did this in a magic ETL. My initial dataset looked like this:

    I then ran the following steps in Magic ETL

    1. Dynamic Unpivot. This is used to stack all of your columns on top of each other.
    2. field number. I create two fields in this step. One to identify the id, request, and column number; and one to designate the field type (field name or value)
    3. Filters for FieldType. This allows me to join the field values to the field names in the next step.
    4. Join Data.
    5. Select Columns.
    6. Pivot. This takes the stacked values and allows me to return them to one row per ID. The key here is that you will need to call out each of the column names that you are wanting to create. If your field names change frequently, this will require a lot of maintenance.
    7. Output Dataset.

Answers

  • ColemenWilson
    edited January 25

    If I am understanding your question correctly, you could use a single formula tile in Magic ETL with a series of case statements to create new fields. To recreate the logic you posted above would be:

    CASE WHEN `customField<0-N>_fieldName` = 'Member_Info_Verified'  THEN `customField<0-N>_fieldValue` END

    You would name this formula something like "Member Info Verified" and then it would appear as a column within your dataset.

    If I solved your problem, please select "yes" above

  • ST_Superman
    ST_Superman Domo Employee
    Answer ✓

    @tmerchant

    I did this in a magic ETL. My initial dataset looked like this:

    I then ran the following steps in Magic ETL

    1. Dynamic Unpivot. This is used to stack all of your columns on top of each other.
    2. field number. I create two fields in this step. One to identify the id, request, and column number; and one to designate the field type (field name or value)
    3. Filters for FieldType. This allows me to join the field values to the field names in the next step.
    4. Join Data.
    5. Select Columns.
    6. Pivot. This takes the stacked values and allows me to return them to one row per ID. The key here is that you will need to call out each of the column names that you are wanting to create. If your field names change frequently, this will require a lot of maintenance.
    7. Output Dataset.