Magic ETL Possibility?

Hi, I'm having an issue. I want to split the fruit column by comma then alphabetize, then bring them back together on their respective account ID. How would I do that in magicETL?
Answers
-
There is a new tile in Magic ETL that is currently in Beta that would allow for this and make it MUCH easier. You can reach out to your CSM to see if you can join the beta for it.
Otherwise, you'll have to use a SQL dataflow and do the following:
1. Create a table in a MYSQL dataflow:
SELECTAccount ID
,
CASE
WHEN LENGTH(Fruit
) - LENGTH(REPLACE(Fruit
, ',', '')) + 1 >= 1 THEN SUBSTRING_INDEX(Fruit
, ',', 1)
ELSE NULL
END ASFruit1
,
CASE
WHEN LENGTH(Fruit
) - LENGTH(REPLACE(Fruit
, ',', '')) + 1 >= 2 THEN SUBSTRING_INDEX(SUBSTRING_INDEX(Fruit
, ',', 2), ',', -1)
ELSE NULL
END ASFruit2
,
CASE
WHEN LENGTH(Fruit
) - LENGTH(REPLACE(Fruit
, ',', '')) + 1 >= 3 THEN SUBSTRING_INDEX(SUBSTRING_INDEX(Fruit
, ',', 3), ',', -1)
ELSE NULL
END ASFruit3
,
CASE
WHEN LENGTH(Fruit
) - LENGTH(REPLACE(Fruit
, ',', '')) + 1 >= 4 THEN SUBSTRING_INDEX(SUBSTRING_INDEX(Fruit
, ',', 4), ',', -1)
ELSE NULL
END ASFruit4
,
CASE
WHEN LENGTH(Fruit
) - LENGTH(REPLACE(Fruit
, ',', '')) + 1 >= 5 THEN SUBSTRING_INDEX(SUBSTRING_INDEX(Fruit
, ',', 5), ',', -1)
ELSE NULL
END ASFruit5
FROMmagic_etl_possibility
2. Create a second table in the dataflow:
SELECTAccount ID
,
TRIM(Fruit1
) AS column_value
FROMtransform_data_1
UNION ALL
SELECTAccount ID
,
TRIM(Fruit2
) AS column_value
FROMtransform_data_1
UNION ALL
SELECTAccount ID
,
TRIM(Fruit3
) AS column_value
FROMtransform_data_1
ORDER BY column_value ASC
3. Create the final table:
SELECT
Account ID
,
GROUP_CONCAT(column_value
SEPARATOR ', ') as 'Alphabetized Fruit!'FROM
transform_data_2
GROUP BYAccount ID
4. Behold the final output:
If I solved your problem, please select "yes" above
0 -
@ColemenWilson , awesome thanks for the answer. I’ll give it a try. Also, name of beta tile so I can request?
0 -
No problem! It's called "Order Tile" for Magic ETL.
If I solved your problem, please select "yes" above
0 -
A more straightforward method rather than multiple CASE WHEN statements is to use SPLIT_PART
SPLIT_PART(`Fruit`, ',', 1) -- First in CSV SPLIT_PART(`Fruit`, ',', 2) -- Second in CSV SPLIT_PART(`Fruit`, ',', 3) -- Third in CSV
**Was this post helpful? Click Agree or Like below**
**Did this solve your problem? Accept it as a solution!**2
Categories
- All Categories
- 2K Product Ideas
- 2K Ideas Exchange
- 1.6K Connect
- 1.3K Connectors
- 311 Workbench
- 6 Cloud Amplifier
- 9 Federated
- 3.8K Transform
- 656 Datasets
- 115 SQL DataFlows
- 2.2K Magic ETL
- 811 Beast Mode
- 3.3K Visualize
- 2.5K Charting
- 80 App Studio
- 45 Variables
- 771 Automate
- 190 Apps
- 481 APIs & Domo Developer
- 77 Workflows
- 23 Code Engine
- 36 AI and Machine Learning
- 19 AI Chat
- AI Playground
- AI Projects and Models
- 17 Jupyter Workspaces
- 410 Distribute
- 120 Domo Everywhere
- 280 Scheduled Reports
- 10 Software Integrations
- 142 Manage
- 138 Governance & Security
- 8 Domo Community Gallery
- 48 Product Releases
- 12 Domo University
- 5.4K Community Forums
- 41 Getting Started
- 31 Community Member Introductions
- 114 Community Announcements
- 4.8K Archive