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.
मित्रांनो! CALCULATE नंतर विद्यार्थी functions स्टिकर्ससारखे जमा करतात. का? प्रत्येक लिखाणात एक युक्ती असते, पण एक पेज नसतो जो सगळे एकत्र धरतो. कसे? FreshBasket च्या दुकानाचा आढावा पाच जुन्या patterns ने बनवायचा, आणि प्रत्येक slicer ने चेक करायचा. आधी वाक्य.
मित्रों! CALCULATE के बाद विद्यार्थी functions स्टिकर की तरह जमा करते हैं. क्यों? हर लेख में एक तरकीब होती है, पर एक पेज नहीं जो सबको साथ रखे. कैसे? FreshBasket दुकान की समीक्षा पाँच पुराने patterns से बनाओ, और हर एक को slicer से चेको. पहले वाक्य.
Quick answer
Vertical board:
- Base:
SUM/DISTINCTCOUNT. - Ratio:
VAR+DIVIDE. - Last year:
CALCULATE+SAMEPERIODLASTYEAR. - Percent of the visual:
DIVIDE+ALLSELECTED. - How many cleared a bar:
COUNTROWS+FILTER+VALUES. - 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.
- Base measure. Rows in: 3.
SUMof Amount out: 200.DISTINCTCOUNTof Order ID out: 2. NoFILTERyet. The slicer did the row cutting. - Ratio. Why
DIVIDE: 200 and 2 are numbers, and orders might be 0 in another city.VARholds 200 and 2.DIVIDEreturns 100. Still no extraFILTER. - Last year. Why a date filter: this year's rows are the wrong rows.
SAMEPERIODLASTYEARbuilds last year's dates.CALCULATEuses that as the filter. Those rows go in, one number comes out. You typeFILTERonly if you are building that date list by hand. - 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.
ALLSELECTEDis that filter change.DIVIDEreturns the share. If you forget it, the percent is 100% on every row because numerator and denominator are the same rows. - How many cities cleared a bar. Why
FILTERhere: the test is the sales measure, so a column filter cannot say it.VALUESlists the cities.FILTERkeeps cities above the bar.COUNTROWSreturns 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:
- Base. All rows in. Sales out: 1160. Distinct orders out: 4 (M-1 is one order). No extra
FILTER. - Slice to Mumbai. Rows in: 500, 200, 300. Sales out: 1000. Orders out: 2. AOV out: 500.
VARholds 1000 and 2.DIVIDEmakes the average. Still no extraFILTER. - 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.
- Percent of what you see. Both cities on the matrix: Mumbai 1000 is about 86% of 1160. Pune 160 is the rest.
ALLSELECTEDlets the denominator see both cities. Forget it, and each row says 100%. - Who cleared a bar. "Cities with sales above 500."
FILTERkeeps Mumbai.COUNTROWSout: 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?
- VAR and RETURN, DIVIDE, last year, percent of total, CALCULATETABLE vs FILTER.
- A marked Date table if pattern 3 is in the page.
- Course: Base measures.
Before and after (look at the tables first)
Before
आधी (Before)
पहले (Before)
After
नंतर (After)
बाद में (After)
Pattern 1 — base measures
Intermediate board: base measure, safe ratio, last-year compare, percent of what is visible, then a threshold count.
मधला फलक: बेस measure, सुरक्षित गुणोत्तर, मागच्या वर्षाशी तुलना, दिसणाऱ्याचा टक्का, मग पट्टी ओलांडलेली संख्या.
बीच का फलक: बेस measure, सुरक्षित अनुपात, पिछले साल से तुलना, दिखने वाले का प्रतिशत, फिर पट्टी पार करने वाली संख्या.
Total Sales = SUM ( Sales[Amount] )
Orders = DISTINCTCOUNT ( Sales[Order ID] )
- Everything else calls these. Do not nest
SUMinside every new idea. - The name is the contract.
Ordersmust not be line count.
Pattern 2 — name it, then divide
Store the pieces in VAR, then DIVIDE — readable ratios, no slash.
तुकडे VAR मध्ये ठेवा, मग DIVIDE — वाचता येणारे गुणोत्तर, स्लॅश नाही.
टुकड़े VAR में रखो, फिर DIVIDE — पढ़ने लायक अनुपात, स्लैश नहीं.
AOV =
VAR SalesAmt = [Total Sales]
VAR OrdersN = [Orders]
RETURN
DIVIDE ( SalesAmt, OrdersN )
- No slash. Empty cities stay blank instead of breaking the page.
- Format the measure.
DIVIDEreturns 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 )
- This needs the Date table. If last year is blank, fix the model before you invent a new function.
- Format
AOV vs LYas a percent.
Pattern 4 — percent of what the reader sees
Pct of Cities =
DIVIDE (
[Total Sales],
CALCULATE ( [Total Sales], ALLSELECTED ( Customer[City] ) )
)
- On a City matrix, rows should add toward 100% of the visible cities.
- An outer slicer should still bite. That is why this is
ALLSELECTED, not a casualALL. - 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
)
)
- The bar is a practice number. Replace it with a real target later.
- The result is a count of cities, not sales.
Write the business sentence first, then pick replace, intersect, last year, or percent of the visual.
आधी धंद्याचे वाक्य लिहा, मग निवडा: बदलून टाकायचे, छेद घ्यायचा, मागले वर्ष, की visual चा टक्का.
पहले धंधे का वाक्य लिखो, फिर चुनो: बदलकर रखना, काटना-मिलाना, पिछला साल, या visual का प्रतिशत.
One page, five cards
Put them on a single report page:
- Card: Total Sales.
- Card: AOV.
- Card: AOV vs LY.
- Matrix: City and Pct of Cities.
- Card: Cities Above.
- 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?
Ravindra Bagale's Tip – मराठी
मुलाखतीचे वाक्य: “मी बेस measures ठेवतो, गुणोत्तर DIVIDE ने, वेळेची सरकती marked Date table वर, टक्के ALLSELECTED ने जेव्हा visual भाजक असतो, आणि FILTER अधिक COUNTROWS जेव्हा measure पास होणाऱ्या वस्तू मोजतो.” पाच वाक्ये. तिथे थांबा. समजलं का?
Ravindra Bagale's Tip – हिंदी
इंटरव्यू की लाइन: “मैं बेस measures रखता हूँ, अनुपात DIVIDE से, समय की सरकन marked Date table पर, प्रतिशत ALLSELECTED से जब visual भाजक हो, और FILTER तथा COUNTROWS जब measure पास करने वाली चीज़ें गिनूँ.” पाँच वाक्य. वहीं रुको. समझ में आया?
Practice task
- Build the five measures on one page.
- Slice a month. Note which cards moved.
- Write the business sentence under each card title.
- Swap
ALLSELECTEDforALLonce and write what changed. - Put the
ALLSELECTEDversion back if the sentence was “what I see”.
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.
समजलं का? मधले काम म्हणजे पाच patterns आणि slicer ची कसोटी, लांब formula नाही. पुढे थोडा वेळ DAX सोडून प्रश्नाला साजेसा chart निवडू. आता पुढे जाऊया.
समझ में आया? बीच का काम पाँच patterns और slicer की कसौटी है, लंबा formula नहीं. आगे थोड़ी देर DAX छोड़कर सवाल के लायक chart चुनेंगे. आगे बढ़ते हैं.
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.