Let’s Get Certified
Module 06 / 08 · Prepare data

Match the query language to the question

A retailer asks which stores exceeded a weekly return threshold and when faults spiked during the week.

Match the query language to the question

A retailer asks which stores exceeded a weekly return threshold and when faults spiked during the week. The sales model supplies business measures, while timestamped faults live in Eventhouse. Put each calculation in the engine that owns its grain and semantics.

At 49:26 the speaker filters grouped SQL results. The KQL and DAX examples later in the chapter answer different questions using event time and model context.

Work through the decision

A SQL author filters for line amounts over 200 and calls the result stores with weekly refunds over 200. What did that calculation miss?

Check your reasoning

Two refunds of 120 at the same store qualify together. Select refunds for the week, group by store and apply the threshold to the sum using HAVING.

DP-600 recording · 49:26

Continue in the recording · 47:54 · 53:11 · 54:39.

Decisions and tradeoffs

SQL HAVING
HAVING filters aggregate groups after grouping.
SQL WHERE
Filter individual rows before the aggregation when the condition describes a source record.
KQL summarize with bin
Bin the event timestamp at the required interval and aggregate events in each bucket.
DAX query-scoped measure
DEFINE MEASURE can introduce a temporary metric in a DAX query without modifying the shared model.
Visual query editor
Use the graphical editor to join, filter and group supported tables and inspect the resulting steps.
KQL where before summarize
Reduce the input by time or event type before aggregating when only those events count.
DAX SUMMARIZECOLUMNS
Group by model attributes and evaluate measures in each resulting filter context.

Compare three query results

Suppose store A has posted refunds of 120 and 95, plus a cancelled refund of 60. Store B has one posted refund of 180.

SELECT StoreId, SUM(Amount) AS RefundTotal
FROM Refunds
WHERE Status = 'Posted'
GROUP BY StoreId
HAVING SUM(Amount) > 200;

Only A qualifies, at 215. Filtering individual refunds over 200 would return no stores.

In an Eventhouse table, count failed checkout events in five-minute buckets.

CheckoutEvents
| where Status == "Failed"
| summarize Failures = count() by bin(EventTime, 5m)
| order by EventTime asc

Failures at 09:02 and 09:04 share the 09:00 bucket. A failure at 09:05 starts the next bucket.

In a semantic model with a related Store dimension, group a temporary measure by store.

DEFINE
    MEASURE Refunds[Posted amount] =
        CALCULATE(SUM(Refunds[Amount]), Refunds[Status] = "Posted")
EVALUATE
    SUMMARIZECOLUMNS(Store[StoreId], "Refunds", [Posted amount])

The measure follows each model group’s filter context. This query shows both A and B. Add an explicit result filter to reproduce the SQL threshold.

Practice each guide skill

Use these prompts in the order of the published guide. Microsoft bullet numbers here are local references.

  1. In the visual editor join products to sales, filter a category and group by store.
  2. Write a SELECT with WHERE, GROUP BY and HAVING. Move the threshold and explain the changed result.
  3. In Eventhouse filter by event type and use summarize with bin on the event timestamp.
  4. Use SUMMARIZECOLUMNS and a query-scoped measure to compare margin by segment.

Official objectives for this lesson

Related lesson · Process events according to when they happened

Knowledge check

Match the query language to the question quiz

Answer 3 questions. Check each answer for an explanation.