Ravindra BagaleCourses & study guides Track your progress

Guides

Common Intermediate DAX Patterns in Power BI

Intermediate DAX is a small set of patterns you can say out loud: base measure, safe ratio, last year, percent of what is on the visual, and “how many cleared the bar”. The function names come after the sentence.

Friends! After CALCULATE, students collect functions like stickers. Why? Each blog shows one trick and no page that holds them together. How? We build one FreshBasket (fictional) ops review from five patterns you already met, and we test each with a slicer. Sentence first.

Quick answer

Vertical board:

  1. Base: SUM / DISTINCTCOUNT.
  2. Ratio: VAR + DIVIDE.
  3. Last year: CALCULATE + SAMEPERIODLASTYEAR.
  4. Percent of the visual: DIVIDE + ALLSELECTED.
  5. How many cleared a bar: COUNTROWS + FILTER + VALUES.
  6. Change one slicer. If the sentence mentioned that slicer, the number must move.
AOV = DIVIDE ( [Total Sales], [Orders] )

One tiny table, five numbers out

Use the same three Pune rows for every pattern so the arithmetic stays visible.

Order ID City Amount
A Pune 100
A Pune 40
B Pune 60

Why a pattern, not a new function each time: the meeting asks five sentences. Each sentence already has a shape.

  1. Base measure. Rows in: 3. SUM of Amount out: 200. DISTINCTCOUNT of Order ID out: 2. No FILTER yet. The slicer did the row cutting.
  2. Ratio. Why DIVIDE: 200 and 2 are numbers, and orders might be 0 in another city. VAR holds 200 and 2. DIVIDE returns 100. Still no extra FILTER.
  3. Last year. Why a date filter: this year's rows are the wrong rows. SAMEPERIODLASTYEAR builds last year's dates. CALCULATE uses that as the filter. Those rows go in, one number comes out. You type FILTER only if you are building that date list by hand.
  4. Percent of the cities on the visual. The row's 200 is the numerator. The denominator must see every city still selected, not only Pune. ALLSELECTED is that filter change. DIVIDE returns the share. If you forget it, the percent is 100% on every row because numerator and denominator are the same rows.
  5. How many cities cleared a bar. Why FILTER here: the test is the sales measure, so a column filter cannot say it. VALUES lists the cities. FILTER keeps cities above the bar. COUNTROWS returns how many names survived. Rows in, test, one count out.

Read a card only after you can point at which rows went in.

Real example: one Saturday, both cities

Put this on paper before you write five measures.

Order City Amount
M-1 Mumbai 500
M-1 Mumbai 200
M-2 Mumbai 300
P-1 Pune 100
P-2 Pune 60

The Mumbai shop's phone bill this month is 699. The Pune shop's phone bill is 399. Target for a bill: stay at or under 500.

What happens, pattern by pattern:

  1. Base. All rows in. Sales out: 1160. Distinct orders out: 4 (M-1 is one order). No extra FILTER.
  2. Slice to Mumbai. Rows in: 500, 200, 300. Sales out: 1000. Orders out: 2. AOV out: 500. VAR holds 1000 and 2. DIVIDE makes the average. Still no extra FILTER.
  3. Last year. The date filter swaps these slips for last March's slips. Different rows in, one number out. That is not the phone bill.
  4. Percent of what you see. Both cities on the matrix: Mumbai 1000 is about 86% of 1160. Pune 160 is the rest. ALLSELECTED lets the denominator see both cities. Forget it, and each row says 100%.
  5. Who cleared a bar. "Cities with sales above 500." FILTER keeps Mumbai. COUNTROWS out: 1. "Months with phone bill above 500" is the same shape on the bill table: March Mumbai stays, 399 and 499 drop, count out is 1.

Say the sentence, then point at the rows, then read the card.

What do I need before this guide?

Before and after (look at the tables first)

Before patterns Ops lines before pattern measures.

Before

After patterns City AOV from sales and orders.

After

Pattern 1 — base measures

Pattern board Intermediate page: base measure, ratio, compare, share, threshold count. Base SUM DIVIDE ratio Share % stack

Intermediate board: base measure, safe ratio, last-year compare, percent of what is visible, then a threshold count.

Total Sales = SUM ( Sales[Amount] )

Orders = DISTINCTCOUNT ( Sales[Order ID] )
  1. Everything else calls these. Do not nest SUM inside every new idea.
  2. The name is the contract. Orders must not be line count.

Pattern 2 — name it, then divide

Name then divide Store pieces in VAR, then DIVIDE so the ratio stays readable. VAR pieces DIVIDE safe Format percent ratio

Store the pieces in VAR, then DIVIDE — readable ratios, no slash.

AOV =
VAR SalesAmt = [Total Sales]
VAR OrdersN = [Orders]
RETURN
    DIVIDE ( SalesAmt, OrdersN )
  1. No slash. Empty cities stay blank instead of breaking the page.
  2. Format the measure. DIVIDE returns a ratio, not a format.

Pattern 3 — same period last year

Sales LY =
CALCULATE (
    [Total Sales],
    SAMEPERIODLASTYEAR ( 'Date'[Date] )
)

AOV vs LY =
VAR NowAOV = [AOV]
VAR LyAOV =
    CALCULATE ( [AOV], SAMEPERIODLASTYEAR ( 'Date'[Date] ) )
RETURN
    DIVIDE ( NowAOV - LyAOV, LyAOV )
  1. This needs the Date table. If last year is blank, fix the model before you invent a new function.
  2. Format AOV vs LY as a percent.

Pattern 4 — percent of what the reader sees

Pct of Cities =
DIVIDE (
    [Total Sales],
    CALCULATE ( [Total Sales], ALLSELECTED ( Customer[City] ) )
)
  1. On a City matrix, rows should add toward 100% of the visible cities.
  2. An outer slicer should still bite. That is why this is ALLSELECTED, not a casual ALL.
  3. If the business sentence is “percent of every city, ignore the slicer”, you picked the wrong pattern. Say the sentence again.

Pattern 5 — how many cleared the bar

Cities Above =
COUNTROWS (
    FILTER (
        VALUES ( Customer[City] ),
        [Total Sales] > 100000
    )
)
  1. The bar is a practice number. Replace it with a real target later.
  2. The result is a count of cities, not sales.
Ask the sentence first Match the pattern to the sentence: replace, intersect, last year, or percent of visible. Sentence first Pattern second Test slicer ask

Write the business sentence first, then pick replace, intersect, last year, or percent of the visual.

One page, five cards

Put them on a single report page:

  1. Card: Total Sales.
  2. Card: AOV.
  3. Card: AOV vs LY.
  4. Matrix: City and Pct of Cities.
  5. Card: Cities Above.
  6. Slicers: Year-Month and, if you want, a region that filters City.

Then ask, out loud, one sentence per card. If you cannot say it, the measure is not finished.

Ghabru naka — you do not need a new function for a new meeting. You need the sentence.

Mistakes and calm fixes

Symptom Likely cause Fix
Percent always 100% Numerator equals denominator Check ALLSELECTED column
Last year blank Date table Mark it and use its date
Cities Above equals 1 Slicer already one city Expected, or clear it
AOV errors Slash, or zero orders DIVIDE

Ravindra Bagale's Tip

Interview line: “I keep base measures, ratios in DIVIDE, time shifts on a marked Date table, percents with ALLSELECTED when the visual is the denominator, and FILTER plus COUNTROWS when I count items that pass a measure.” Five sentences. Stop there. Got it?

Practice task

  1. Build the five measures on one page.
  2. Slice a month. Note which cards moved.
  3. Write the business sentence under each card title.
  4. Swap ALLSELECTED for ALL once and write what changed.
  5. Put the ALLSELECTED version back if the sentence was “what I see”.

Learn it properly

Course lessons:

Related guides: ALL family · YoY · Percent of total

Got it? Intermediate work is five patterns and a slicer test, not a longer formula. Next we leave DAX for a minute and choose the chart that fits the question. Let's continue.

Frequently asked questions

Do I memorise every function?

No. Memorise the sentence each pattern answers, then the shape of the measure.

Which pattern is percent of total?

DIVIDE the row value by CALCULATE of the same measure with ALLSELECTED (or ALL, if you mean the whole column).

Which pattern is “how many cities are above X”?

COUNTROWS of FILTER on VALUES of City, testing the measure.

Where do variables fit?

Anywhere the measure has two or more pieces. Name them, then RETURN the final expression.

What should I test?

One slicer change. If the sentence says “selected cities”, the number must move when the slicer moves.

Course lessons?

Base measures and CALCULATE in the DAX chapter, plus the pattern guides linked below.