1. Lighthouse

Level 7 · Merge in the category, then group the returns

The request

From Angela Rivera, Head of Customer Support

“Our support tool exports October's returns with the product id but no category. For the quality meeting I need, per category, how many returns we had and how much we refunded, biggest refunds first. The product list is already in Power Query as a query called Products.”

Your goal

The Source step is October 2025's 44 returns (return_id, order_item_id, product_id, returned_on, reason, refund_amount). Merge the Products query on product_id and expand category, then group by category with returns = the number of rows and refunded = the sum of refund_amount, sorted by refunded, biggest first.

  • Show exactly category returns refundednot done yet
  • 6 rows, sorted as askednot done yet

Your query steps

Power Query
The sheet for this level
return_idorder_item_idproduct_idreturned_onreasonrefund_amount
11434254181662025-10-01changed_mind28.99
21435254501662025-10-02wrong_item28.99
31436246411542025-10-04changed_mind23.98
41437254191682025-10-04damaged159
51438248271602025-10-05changed_mind141.98
61439251161372025-10-05late219
71440254201942025-10-05damaged159
81441252291872025-10-06late149
91442256331462025-10-06damaged67.96
101443257361382025-10-06damaged398
111444253181542025-10-08changed_mind143.88
121445256351842025-10-09wrong_item35.98
131446252301772025-10-10changed_mind169
141447257321342025-10-11damaged185.98
151448258011802025-10-11wrong_item20.99
161449258181742025-10-12changed_mind18.99
171450257461622025-10-13wrong_item23.99
181451251341642025-10-14changed_mind52.99
191452256341582025-10-15late179
201453259761542025-10-15damaged35.97
211454258201712025-10-17changed_mind27.99
221455259631662025-10-18damaged28.99
231456259951982025-10-18damaged134.97
241457254212032025-10-19late107.98
251458259781282025-10-19wrong_item54.99
261459251281102025-10-20late179
271460252931932025-10-20changed_mind39.98
281461260411922025-10-20damaged15.99
291462261141222025-10-20damaged29.99
301463260091742025-10-21wrong_item56.97
311464259752182025-10-22wrong_item779
321465260101992025-10-22wrong_item104.99
331466260401842025-10-22damaged17.99
341467260441342025-10-22wrong_item92.99
351468261931712025-10-22wrong_item27.99
361469261711962025-10-24wrong_item25.99
371470259042122025-10-25changed_mind982.6
381471261622032025-10-25damaged323.94
391472261521742025-10-26damaged18.99
401473262981802025-10-26wrong_item20.99
411474257841582025-10-27late179
421475259871542025-10-30late11.99
431476262861562025-10-30damaged53.99
441477264191532025-10-30wrong_item72.99

Loading the editor…

    ResultPress Check to compare the query result

    Mote checks your result

    Press Check. Mote fills in your answer and compares it with what the report needs.

    The lesson

    Angela’s export knows which product came back but not what kind of product it is. Two steps fix that: a merge that looks the category up, and a group by that turns 44 rows into one row per category.

    Merge: look up the category

    Merge queries: Products on product_id, expand category

    In Power BI: select the returns query, Home → Merge Queries, choose Products as the second table, click product_id in both previews, keep Left Outer, OK. Power Query adds a column holding, for each return, the matching rows of Products. Click the expand icon (two arrows) on its header, tick only category, and untick Use original column name as prefix so the column is called category and not Products.category. Two steps are recorded:

    Table.NestedJoin(Source, {"product_id"}, Products, {"product_id"}, "Products", JoinKind.LeftOuter)
    Table.ExpandTableColumn(#"Merged Queries", "Products", {"category"}, {"category"})

    Check the match count at the bottom of the Merge dialog: all 44 returns should find their product. A null category after expanding means a product missing from the list.

    Group by: one row per category

    Group by: category | returns = count rows | refunded = sum of refund_amount

    In Power BI: Home → Group By (or Transform → Group By), choose Advanced to add more than one aggregation. Group by category; first aggregation: new column name returns, operation Count Rows; Add aggregation: refunded, operation Sum, column refund_amount. Other operations: Average, Median, Min, Max, Count Distinct Rows, and All Rows, which keeps the grouped rows as a nested table. Columns not grouped or aggregated are dropped, which is what a summary is.

    Table.Group(#"Expanded Products", {"category"},
        {{"returns", each Table.RowCount(_), Int64.Type},
         {"refunded", each List.Sum([refund_amount]), type number}})

    Sort, biggest first

    Sort rows: refunded descending

    Click the arrow on the refunded header → Sort Descending. In a report you’d usually sort in the visual instead; here the table itself goes to Angela.

    What it shows

    category returns refunded
    Outdoor 4 2,193.52
    Lighting 6 980.95
    Kitchen 10 910.74
    Textiles 14 684.86
    Decor 9 683.89
    Furniture 1 179.00

    Textiles had the most returns, Outdoor the most money back from just four items. Bring both columns to the meeting: the count is the support team’s workload, the refund total is the cost.

    Group in Power Query, or in the model?

    Grouping in Power Query loads only the summary: small and fast, but nobody can drill into a single return. For a report you’d usually load all 44 rows and let a measure do the totals, so slicers on reason or date still work. Group in Power Query when the detail is never needed.

    Common mistakes

    • Expanding every Products column. name and a duplicate product_id clutter the table.
    • Sum of return_id. A sum of IDs is a meaningless number; count rows instead.
    • Forgetting to rename. Count and Sum as column names mean nothing next month.

    Pick what may run on this site. You can change this any time from "Cookie settings" at the bottom of every page.