Check your eligibility for this 50% exam voucher offer and join us for free live learning sessions to get prepared for Exam DP-700.
Get StartedJoin us at the 2025 Microsoft Fabric Community Conference. March 31 - April 2, Las Vegas, Nevada. Use code FABINSIDER for $400 discount. Register now
Problem description
As described in the teaser above - sometimes you need to create additional "helping" queries, which might not be optimal and your number of queries can enormously grow.
Let's take a look at simple example here:
I have one query with basic information like Order ID, Customer ID, Revenue etc.
We assume that one customer can have multiple orders. What if we want to bring information about average revenue by Customer ID? Something like this:
With a basic approach you could create two separate queries and merge them together:
But why to duplicate some steps (because referencing a whole query and combining it again with original does not work), if you can avoid it?
I will explain in next steps.
Solution description
1. Let me introduce my easy query:
As you can see I barely do any transformations, only changing some data types and removing unncessary columns.
2. In my next step I need to find the average revenue for each Client ID. The easiest way is just to use Group By with Average. To better demonstrate my result I will also do simple count of orders for each Client ID.
Which results into:
3. Now we need to bring those aggregated results back to our original step. If you remember, it was called "Removed Other Columns". We can do it by merging TWO STEPS into one:
As you can see above I am mixing to different query steps in Merge operation. My initial "Removed Other Columns" is used as a left table and later "Grouped Rows" as right table.
Result of the step looks like this:
4. At this moment we can just simple expand Agg Data column.
5 (TEST). So far we can' really tell if the result is correct, so just for testing purposes I will filter on Client IDs, where we have multiple orders:
As we can see, the Average matches with our column.
Final note: You can do those references not only with merge, but with different transformations like append, custom column and more!
In case of any questions - let me know either here or ask on my Linkedin profile:
https://www.linkedin.com/in/milan-mejzr-74884012a/
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.