Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
Danijel
Partner - Creator III
Partner - Creator III

Enrich data after Grouping

Hello together,

I have the following issue. I have a large table in which I have data for calculation.

In one step, I limit relevant data sets with a Where condition and group them. I use the grouping with only a few fields from the original table.

With this data, I determine some flags and KPIs and concatenate them back to the original table.

Now the problem: because of the grouping at the beginning, I can't pull all the data into the load, so I'm now missing almost 75% of the contents of the fields that I didn't use.

Do you have any ideas on how I can fill these in?

Thanks and greetings

Labels (1)
2 Replies
rubenmarin

Hi, I'm not sure to understand... if that enriched data has only vaue for each group you can do a join or a mapping to add new fields.

If each group can have different values you will need an additional table with detailed data and realted them with a composite key using the grouped values to relate rows.

If you do a concatenate you are adding new rows, so new rows doesn't have old fields and old rows doesn't have new fields.

Forlorn
Contributor
Contributor

Two potential solutions to this issue are to use b2b data enrichment tools or a JOIN operation to rejoin the grouped data with the original table, using a common key or set of keys. This will allow you to bring in all the missing fields that you need.

For example, let's say that you grouped your data by a field called "customer_id", and you only used the fields "customer_id", "product_id", and "order_date" in your grouping. You can then join this grouped data back to the original table using the "customer_id" field as the common key, and bring in all the missing fields that you need.

Here is an example SQL query that you can use:

SELECT *
FROM original_table
JOIN (
SELECT customer_id, MAX(order_date) as max_order_date, COUNT(*) as order_count
FROM original_table
WHERE <your WHERE condition here>
GROUP BY customer_id
) grouped_data
ON original_table.customer_id = grouped_data.customer_id
AND original_table.order_date = grouped_data.max_order_date

In this example, we are joining the original table with the grouped data using the "customer_id" field as the common key. We are also using the "MAX" and "COUNT" aggregation functions to determine some flags and KPIs in the grouped data.

By using a JOIN operation like this, you should be able to bring in all the missing fields that you need from the original table.

I hope this helps! Let me know if you have any further questions.