Add group by as an additional field
Hi everyone,
I am looking to add a column to a dataset where I join all my users and their orders (could be 1 or more) and get a count of how many orders an individual user has placed. I pulled all the columns I want in my ETL dataflow, and then calculated this field using the "Group By" transformation. I group by 'user_id' and aggregate my order_id's as a count.
This gets me the right data, but then the only columns I am left with are the 2 from the Group By transformation, with all the others dropped (i.e., name, email, city, order info, etc.). Is there a way to get the counts of each user's total orders and add this as an additional column where I have 1 row per distinct user_id? I tried both an ETL dataflow and a SQL transform but nothing worked. I can get the exact data I want going directly to the SQL database, but would like to do this directly in Domo and get a card created/updated automatically.
Thanks for the help!!
Best Answer
-
It sort of worked, but still wasn't exactly what I was trying to accomplish. I solved this by using a dense_rank function.
0
Answers
-
This should be doable. Would you mind sharing what your ETL looks like, and where you are running into issues?
0 -
I am joining the data based on the user_id's in both tables. Then I group by the user_id from the Users table and count the order_id's from the Orders table. This drops all my other columns and leaves me with just the two columns that get pulled into the Group By transform. I want the Count column to be added as an additional field while maintaining all my other data.
0 -
Just add the extra columns in step 1 of the group by tile.
Keep in mind that if any of the columns you add to that step contain different values, you should move it down to the second step and create an aggregate calculation
0 -
That defeats the purpose of grouping by the user_id. That is still outputting multiple rows for an individual user_id. If a user has 3 orders it displays 3 rows. I want to consolidate this into 1 row.
0 -
Any column that you list in step 1 will cause a new row of data in your output for every unique combination. For example, if you have several different product families that you sell to customers, you can use something like this to get total sales grouped by account and product family:
Or, if you remove "Product Family" from the first step, you can see total sales grouped only be customer:
0 -
Is there a way to add just a single Count aggregate column while also maintaining all the other data for a single user? Some of the data might be different for various fields (such as order_date which is different for each order), but I want just 1 column for a user with a given name, email, etc. and all the other info relating to that row.
I know it can be done easily with SQL, but looking to move away from that and make this reusable with a Domo card.
0 -
Yes, just don't inlcude order date in the list of fields. Otherwise you will want to add order date to the second section and create a "group by" field that would show you the Max of the order date as the most recent order.
0 -
0
-
I tried that and it still outputs multiple rows for each order. I grouped by order_id and the order_date (taking the max(order_date) as most recent), but it still outputs 2 rows for a user with 2 orders.
0 -
If you group by Order ID then you will get a separate row for each order ID. You want to group by Customer. You can't have Order ID in your output if you are wanting to combine data from multiple orders.
1 -
Basically, if you are wanting to group by customer, then you can list all Customer relevant fields (the fields that will always have the same value for the same customer) in step 1 of the group by tile. All Order information will need to be aggregated and listed in section 2 of the group by tile.
1 -
0
-
It sort of worked, but still wasn't exactly what I was trying to accomplish. I solved this by using a dense_rank function.
0 -
Can you share your solution so others may benefit from this thread?
Thanks!
0 -
To clarify can you share the dense rank function in a reply?
0
Categories
- All Categories
- 1.8K Product Ideas
- 1.8K Ideas Exchange
- 1.6K Connect
- 1.2K Connectors
- 300 Workbench
- 6 Cloud Amplifier
- 9 Federated
- 2.9K Transform
- 102 SQL DataFlows
- 626 Datasets
- 2.2K Magic ETL
- 3.9K Visualize
- 2.5K Charting
- 753 Beast Mode
- 61 App Studio
- 41 Variables
- 692 Automate
- 177 Apps
- 456 APIs & Domo Developer
- 49 Workflows
- 10 DomoAI
- 38 Predict
- 16 Jupyter Workspaces
- 22 R & Python Tiles
- 398 Distribute
- 115 Domo Everywhere
- 276 Scheduled Reports
- 7 Software Integrations
- 130 Manage
- 127 Governance & Security
- 8 Domo Community Gallery
- 38 Product Releases
- 11 Domo University
- 5.4K Community Forums
- 40 Getting Started
- 30 Community Member Introductions
- 110 Community Announcements
- 4.8K Archive