Complete DAX Queries Of Power BI
Power BI DAX Complete Formula List
Row context vs filter context, CALCULATE, time intelligence, REMOVEFILTERS aur business measures tak — har DAX concept ka syntax, example aur behaviour. Common traps aur interview one-liners ke saath. Power BI DAX complete cheat sheet.
📑 Is Article Mein Kya Hai:
- 🧠 PART 0 — DAX ka Core Concept (yeh samjho, sab aasan)
- 🧱 PART 1 — Base Aggregation Measures
- ➗ PART 2 — DIVIDE (sabse zaroori function)
- 🎯 PART 3 — CALCULATE (DAX ka dil)
- 📅 PART 4 — Time Intelligence (Interview ka favourite)
- 🔓 PART 5 — Filter Modifiers (ALL family)
- 🔁 PART 6 — Iterators (X-functions)
- 🧲 PART 7 — Context Functions (advanced but impressive)
- 🎨 PART 8 — Conditional Formatting / Dynamic Measures
- 🚚 PART 9 — Business Measures (Supply Chain)
- 🏗️ PART 10 — Calculated Column vs Measure
- 🧮 PART 11 — Useful DAX Functions Quick List
- 🚫 PART 12 — Common DAX Mistakes (tumhare bhi the)
- 🎤 PART 13 — Interview One-Liners (DAX)
- ✅ Revision Priority
- 🏗️ Bonus — Star Schema Template
🧠 PART 0 — DAX ka Core Concept (yeh samjho, sab aasan)
DAX me sirf 2 context hote hain. 90% confusion yahin se aati hai.
| Row Context | Filter Context | |
|---|---|---|
| Kya hai | "Abhi kaunsi row pe hoon" | "Kaunsi rows allowed hain" |
| Kahan banta hai | Calculated column, iterators (SUMX, FILTER) | Visual, slicer, CALCULATE |
| Model filter karta hai? | ❌ Nahi | ✅ Haan |
| Relationships se propagate? | ❌ Nahi | ✅ Haan |
CALCULATE ka kaam = Row Context ko Filter Context me convert karna. Isko Context Transition kehte hain. Yeh ek line interview me bol do — banda impress ho jayega.
-- Yeh measure hai (filter context me chalta hai) ✅
Total Sales = SUM(Sales[Sales_Amount])
-- Yeh calculated column me galat kaam karega ❌
-- kyunki calculated column me filter context hota hi nahi
🧱 PART 1 — Base Aggregation Measures
-- Basic ⭐
Total Sales = SUM(Sales[Sales_Amount])
Total Orders = COUNT(Sales[Order_ID]) -- NULL skip karta hai
Total Rows = COUNTROWS(Sales) -- saari rows ⭐
Distinct Orders = DISTINCTCOUNT(Sales[Order_ID]) -- unique count ⭐
Blank Rows = COUNTBLANK(Sales[Discount])
Average Price = AVERAGE(Sales[Unit_Price])
Max Sale = MAX(Sales[Sales_Amount])
Min Sale = MIN(Sales[Sales_Amount])
Total Cost = SUM(Sales[Unit_Cost])
Total Profit = [Total Sales] - [Total Cost] -- measure ko [ ] me reference karo ⭐
⚠️ AVERAGE ka classic trap
-- ❌ GALAT: pehle row-level average, phir unka average
Wrong Avg = AVERAGE(Sales[Sales_Amount])
-- ✅ SAHI: aggregate karo, phir divide karo
Avg Order Value = DIVIDE([Total Sales], [Total Orders])
aggregate karo, phir
DIVIDE karo. Yeh interview me pakka poocha jata hai.➗ PART 2 — DIVIDE (sabse zaroori function)
-- ❌ KABHI aisa mat likho
Margin % = ([Total Sales] - [Total Cost]) / [Total Sales] -- divide by zero = ERROR
-- ✅ SAHI ⭐
Margin % = DIVIDE([Total Sales] - [Total Cost], [Total Sales], 0)
Syntax: DIVIDE(numerator, denominator, alternateResult)
- Teesra argument = alternate result (divide-by-zero pe yeh return hoga)
- Isko likhna hi chahiye — warna
BLANKyaInfinityaa jayega
Golden Rule: * 100 mat karo ⭐
-- ❌ GALAT
OTD % = DIVIDE([On Time], [Total], 0) * 100
-- ✅ SAHI
OTD % = DIVIDE([On Time], [Total], 0)
Measure ki value 0.625 rehne do, aur Power BI me Format → Percentage kar do. Display 62.50% dikhega. Isse conditional formatting aur gauges sahi kaam karte hain.
🎯 PART 3 — CALCULATE (DAX ka dil)
-- Syntax: CALCULATE(<expression>, <filter1>, <filter2>, ...)
-- Simple filter ⭐
On Time Shipments = CALCULATE([Total Shipments], Shipments[Delivery_Status] = "On-Time")
-- Multiple conditions (AND)
Big COD Orders = CALCULATE([Total Orders],
Orders[Payment_Mode] = "COD",
Orders[Order_Amount] > 10000)
-- OR condition
Priority Orders = CALCULATE([Total Orders],
Orders[Priority] = "High" || Orders[Priority] = "Urgent")
-- FILTER() function se (complex condition ke liye) ⭐
High Value Orders = CALCULATE([Total Orders],
FILTER(Orders, Orders[Order_Amount] > 10000 && Orders[Units] > 5))
-- Boolean vs FILTER — performance ⭐
-- Simple comparison → Boolean expression use karo (VertiPaq optimize karta hai)
-- Row-by-row complex logic → FILTER() use karo (Formula Engine, slow)
🏆 The Classic OTD % (interview standard answer)
Total Shipments = COUNTROWS(Shipments)
On Time Shipments = CALCULATE([Total Shipments], Shipments[Delivery_Status] = "On-Time")
OTD % = DIVIDE([On Time Shipments], [Total Shipments], 0)
Single-measure VAR version (yeh zyada professional lagta hai):
OTD % =
VAR TotalCount = COUNTROWS(Shipments)
VAR OnTimeCount = CALCULATE(COUNTROWS(Shipments), Shipments[Delivery_Status] = "On-Time")
RETURN
DIVIDE(OnTimeCount, TotalCount, 0)
📅 PART 4 — Time Intelligence (Interview ka favourite)
⚠️ Pehle: Date Table BANAO (yeh mandatory hai)
DimDate = CALENDARAUTO() -- data ke hisaab se auto range
-- Ya custom
DimDate = CALENDAR(DATE(2023,1,1), DATE(2026,12,31))
-- Columns add karo
DimDate =
ADDCOLUMNS(
CALENDARAUTO(),
"Year", YEAR([Date]),
"Quarter", "Q" & FORMAT([Date], "Q"),
"Month No", MONTH([Date]),
"Month Name", FORMAT([Date], "MMM"),
"Month Year", FORMAT([Date], "MMM-YYYY"),
"Day Name", FORMAT([Date], "DDDD"),
"Is Weekday", WEEKDAY([Date], 2) <= 5
)
Phir: Model view → DimDate[Date] pe right-click → "Mark as Date Table" ✅
Yeh line interview me bolna = tumhe modelling aati hai.
4.1 Previous Period ⭐
Previous Month Sales = CALCULATE([Total Sales], PREVIOUSMONTH(DimDate[Date]))
Previous Quarter = CALCULATE([Total Sales], PREVIOUSQUARTER(DimDate[Date]))
Previous Year Sales = CALCULATE([Total Sales], PREVIOUSYEAR(DimDate[Date]))
Last Year Same Period= CALCULATE([Total Sales], SAMEPERIODLASTYEAR(DimDate[Date]))
4.2 DATEADD — custom offset ⭐
Sales 1 Month Ago = CALCULATE([Total Sales], DATEADD(DimDate[Date], -1, MONTH))
Sales 3 Month Ago = CALCULATE([Total Sales], DATEADD(DimDate[Date], -3, MONTH))
Sales Last Year = CALCULATE([Total Sales], DATEADD(DimDate[Date], -1, YEAR))
Next Month Sales = CALCULATE([Total Sales], DATEADD(DimDate[Date], 1, MONTH))
🔥 PREVIOUSMONTH vs DATEADD vs PARALLELPERIOD (doc-verified)
PREVIOUSMONTH | DATEADD(-1, MONTH) | PARALLELPERIOD(-1, MONTH) | |
|---|---|---|---|
| Kya return karta hai | Pura previous calendar month | Context ki har date ko 1 month peeche shift | Pura previous calendar month |
| Partial month context me | Pura March dega | Sirf wahi days dega (1–15 March) | Pura March dega |
| Multi-month shift | ❌ sirf -1 | ✅ koi bhi N | ✅ koi bhi N |
| Total row pe | BLANK aa sakta hai | Sum of months | Sum of months |
SQLBI ke mutabiq: PREVIOUSMONTH(X) internally = PARALLELPERIOD(FIRSTDATE(X), -1, MONTH)
PREVIOUSYEAR / PREVIOUSMONTH **BLANK return karte hain jabfilter context me multiple years/months ho** (jaise grand total row). Standard reports me
DATEADD ya SAMEPERIODLASTYEAR zyada reliable hain.4.3 Cumulative Periods ⭐
MTD Sales = TOTALMTD([Total Sales], DimDate[Date])
QTD Sales = TOTALQTD([Total Sales], DimDate[Date])
YTD Sales = TOTALYTD([Total Sales], DimDate[Date])
-- Custom year end (Indian FY = 31 March) ⭐
FY YTD Sales = TOTALYTD([Total Sales], DimDate[Date], "3/31")
4.4 Growth Measures ⭐
-- Month-over-Month
MoM Sales Growth % =
VAR CurrentSales = [Total Sales]
VAR PrevSales = [Previous Month Sales]
RETURN
DIVIDE(CurrentSales - PrevSales, PrevSales, 0)
-- Year-over-Year
LY Sales = CALCULATE([Total Sales], SAMEPERIODLASTYEAR(DimDate[Date]))
YoY Growth % =
VAR Curr = [Total Sales]
VAR LY = [LY Sales]
RETURN
DIVIDE(Curr - LY, LY, 0)
-- Absolute difference
MoM Sales Variance = [Total Sales] - [Previous Month Sales]
4.5 Rolling / Moving Average ⭐
Rolling 3 Month Sales =
CALCULATE(
[Total Sales],
DATESINPERIOD(DimDate[Date], LASTDATE(DimDate[Date]), -3, MONTH)
)
Rolling 7 Day Sales =
CALCULATE(
[Total Sales],
DATESINPERIOD(DimDate[Date], LASTDATE(DimDate[Date]), -7, DAY)
)
Rolling 3M Avg = DIVIDE([Rolling 3 Month Sales], 3)
DATESINPERIOD = SQL ke ROWS BETWEEN 6 PRECEDING ka DAX version.4.6 Other Date Helpers
First Sale Date = FIRSTDATE(DimDate[Date])
Last Sale Date = LASTDATE(DimDate[Date])
Days in Month = COUNTROWS(DATESMTD(DimDate[Date]))
Working Days = COUNTROWS(FILTER(DATESBETWEEN(...), WEEKDAY([Date],2) <= 5))
Same Period Next = CALCULATE([Total Sales], NEXTMONTH(DimDate[Date]))
🔓 PART 5 — Filter Modifiers (ALL family)
-- ALL: saare filters hata do ⭐
Sales All Products = CALCULATE([Total Sales], ALL(Product))
Sales All Regions = CALCULATE([Total Sales], ALL(Geography[Region]))
-- ALLEXCEPT: yeh column chhod ke baaki sab hata do
Sales per Product = CALCULATE([Total Sales], ALLEXCEPT(Sales, Product[Product_Name]))
-- ALLSELECTED: visual ke filters hatao, slicer ke rakho ⭐
Sales All Selected = CALCULATE([Total Sales], ALLSELECTED(Product[Category]))
-- REMOVEFILTERS: Microsoft ka recommended (intent clear hota hai) ⭐
Sales Clear Filter = CALCULATE([Total Sales], REMOVEFILTERS(Product))
-- KEEPFILTERS: existing filter ko override hone se bachao
West Sales = CALCULATE([Total Sales], KEEPFILTERS(Geography[Region] = "West"))
🏆 % of Total (sabse common dashboard measure)
-- % of grand total
% of Total Sales = DIVIDE([Total Sales], CALCULATE([Total Sales], ALL(Product)), 0)
-- % within slicer selection (visual total ke against)
% of Selected = DIVIDE([Total Sales], CALCULATE([Total Sales], ALLSELECTED(Product)), 0)
-- % of parent category ⭐ (SQLBI recommended pattern)
% of Category =
DIVIDE(
[Total Sales],
CALCULATE([Total Sales], REMOVEFILTERS(Product), VALUES(Product[Category]))
)
Comparison table (doc-verified)
| Function | Kya karta hai | Kab use karo |
|---|---|---|
ALL(T) | Table/column ke saare filters hatao | Grand total ke against % |
ALLEXCEPT(T, col) | Sirf col ka filter rakho | Group subtotal |
ALLSELECTED(col) | Visual filters hatao, slicer rakho | "% of selected" |
REMOVEFILTERS(T) | Filters hatao (clear intent) | Microsoft recommended ✅ |
KEEPFILTERS(...) | Existing filter ko preserve karo | AND logic chahiye tab |
FILTER(T, ...) | Row-by-row condition | Complex logic only |
ALLEXCEPT ki jagah REMOVEFILTERS + VALUES combo use karo —kyunki
ALLEXCEPT expanded table (related dimensions) ke filters bhi hata deta hai,jisse unexpected results aa sakte hain.
🔁 PART 6 — Iterators (X-functions)
-- SUMX: row-by-row calculate karo, phir sum ⭐
Total Revenue = SUMX(Sales, Sales[Units] * Sales[Unit_Price])
-- Profit per row, phir total
Total Profit = SUMX(Sales, (Sales[Unit_Price] - Sales[Unit_Cost]) * Sales[Units])
-- AVERAGEX
Avg Line Value = AVERAGEX(Sales, Sales[Units] * Sales[Unit_Price])
-- COUNTX / MINX / MAXX
Max Line Value = MAXX(Sales, Sales[Units] * Sales[Unit_Price])
-- FILTER + SUMX
High Value Revenue = SUMX(FILTER(Sales, Sales[Order_Amount] > 10000),
Sales[Units] * Sales[Unit_Price])
-- RELATED (dusri table se value laao — row context me) ⭐
Line Total with Cost = SUMX(Sales, Sales[Units] * RELATED(Product[Unit_Cost]))
-- RELATEDTABLE (ulta direction — one-to-many)
Order Count per Customer = COUNTROWS(RELATEDTABLE(Sales))
SUM vs SUMX — kab kya?
SUM(col) | SUMX(table, expr) | |
|---|---|---|
| Kab | Column already exist karta ho | Row-level calculation karni ho |
| Speed | Fast (columnar) | Slower (row iteration) |
| Example | SUM(Sales[Amount]) | SUMX(Sales, Qty * Price) |
SUM use karo — performance better.🧲 PART 7 — Context Functions (advanced but impressive)
VALUES(Product[Category]) -- current context ki distinct values (table)
SELECTEDVALUE(Product[Category]) -- single value, warna BLANK ⭐
HASONEVALUE(Product[Category]) -- True/False
ISFILTERED(Sales[Order_Date]) -- kya filter laga hai?
ISCROSSFILTERED(Product[Product_ID])
DISTINCTCOUNT(Product[Product_ID])
-- Dynamic title banane ke liye ⭐
Dynamic Title =
VAR Sel = SELECTEDVALUE(Product[Category], "All Categories")
RETURN "Sales Report — " & Sel
-- Conditional measure
Sales Display =
IF(HASONEVALUE(Product[Category]), [Total Sales], BLANK())
SELECTEDVALUE(col) = IF(HASONEVALUE(col), VALUES(col), BLANK()) ka shortcut.Microsoft bhi yehi recommend karta hai.
🎨 PART 8 — Conditional Formatting / Dynamic Measures
-- Status flag (conditional formatting ke liye) ⭐
Delivery Status Color =
SWITCH(
TRUE(),
[OTD %] >= 0.95, "#00A651", -- green
[OTD %] >= 0.85, "#FFA500", -- orange
"#E81123" -- red
)
-- RAG status text
RAG Status =
SWITCH(
TRUE(),
[OTD %] >= 0.95, "🟢 On Track",
[OTD %] >= 0.85, "🟠 At Risk",
"🔴 Critical"
)
-- IF version
Stock Alert =
IF([Days of Stock] <= [Lead Time Days], "🔴 Reorder Now",
IF([Days of Stock] <= [Lead Time Days] * 1.5, "🟠 Watch", "🟢 Safe"))
-- Data bars / icons ke liye numeric
Stock Score =
VAR DOS = [Days of Stock]
RETURN
IF(DOS <= 7, 1, IF(DOS <= 15, 2, 3))
SWITCH(TRUE(), ...) vs nested IF ⭐
- 3+ conditions ho toh
SWITCH(TRUE())use karo — padhne me aasan, performance better - Nested
IFsirf 2 conditions tak
🚚 PART 9 — Business Measures (Supply Chain)
-- On-Time Delivery % ⭐
OTD % = DIVIDE([On Time Shipments], [Total Shipments], 0)
-- Fill Rate
Fill Rate % = DIVIDE(SUM(Shipments[Units_Delivered]), SUM(Shipments[Units_Ordered]), 0)
-- OTIF (On-Time In-Full) — dono condition ek saath ⭐
OTIF % =
DIVIDE(
CALCULATE([Total Shipments],
Shipments[On_Time_Flag] = 1,
Shipments[Complete_Flag] = 1),
[Total Shipments],
0
)
-- SLA Breach %
SLA Breach % =
DIVIDE(
CALCULATE([Total Shipments], Shipments[Actual_Date] > Shipments[Promised_Date]),
[Total Shipments],
0
)
-- Days of Stock ⭐
Days of Stock = DIVIDE(SUM(Inventory[Current_Stock]), [Daily Avg Sales])
Daily Avg Sales =
DIVIDE(
CALCULATE([Total Units Sold],
DATESINPERIOD(DimDate[Date], LASTDATE(DimDate[Date]), -30, DAY)),
30
)
-- Reorder Point = (Avg Daily Sales × Lead Time) + Safety Stock
Reorder Point = ([Daily Avg Sales] * [Avg Lead Time]) + [Safety Stock]
-- Safety Stock = Z × σ(demand) × √lead_time
Safety Stock =
VAR Z = 1.65 -- 95% service level
VAR Sigma = CALCULATE(STDEV.P(Sales[Units]))
VAR LT = [Avg Lead Time]
RETURN Z * Sigma * SQRT(LT)
-- Inventory Turnover
Inventory Turnover = DIVIDE([Total COGS], [Average Inventory Value])
-- Days of Inventory
DOH = DIVIDE(365, [Inventory Turnover])
-- Return Rate / RTO %
RTO % = DIVIDE([Returned Orders], [Total Orders], 0)
-- Cost per Delivery
Cost per Delivery = DIVIDE([Total Logistics Cost], [Total Shipments])
-- ABC classification (calculated column)
ABC Class =
VAR CumPct = Inventory[Cumulative Revenue %]
RETURN
IF(CumPct <= 0.80, "A", IF(CumPct <= 0.95, "B", "C"))
💳 Fraud Measures (Mastercard)
High Risk Txns =
CALCULATE([Total Transactions], Transactions[Risk_Flag] = "High Risk")
Fraud Rate % = DIVIDE([High Risk Txns], [Total Transactions], 0)
Off Hour Txns =
CALCULATE([Total Transactions],
FILTER(Transactions, HOUR(Transactions[Txn_Time]) >= 2 &&
HOUR(Transactions[Txn_Time]) <= 4))
-- Card velocity flag (calculated column)
Velocity Flag =
VAR PrevTime = CALCULATE(MAX(Transactions[Txn_Time]),
FILTER(Transactions, Transactions[Txn_Time] < EARLIER(Transactions[Txn_Time]) &&
Transactions[Card_Number] = EARLIER(Transactions[Card_Number])))
RETURN IF(DATEDIFF(PrevTime, Transactions[Txn_Time], MINUTE) <= 10, "High Velocity", "Normal")
🏗️ PART 10 — Calculated Column vs Measure
-- Calculated COLUMN (row context me, model me store hota hai)
Sales[Line Total] = Sales[Units] * Sales[Unit_Price]
Sales[Delivery TAT] = DATEDIFF(Sales[Promised_Date], Sales[Actual_Date], DAY)
Sales[Order Month] = FORMAT(Sales[Order_Date], "MMM-YYYY")
-- MEASURE (filter context me, on-the-fly calculate hota hai)
Total Line Sales = SUM(Sales[Line Total])
| Calculated Column | Measure | |
|---|---|---|
| Kab compute hota hai | Data refresh pe (stored) | Query time pe (dynamic) |
| Context | Row context | Filter context |
| Memory | ✅ Leti hai (column store) | ❌ Nahi leti |
| Slicer/filter me use | ✅ Ho sakta hai | ❌ Nahi (visual values me hi) |
| Time intelligence | ❌ Galat result dega | ✅ Sahi |
| Kab use karo | Slicer/filter chahiye tab | Default choice ✅ |
PREVIOUSMONTH, TOTALYTD) ko **calculated column memat daalo** — calculated column me filter context hota hi nahi, isliye result galat aayega.
🧮 PART 11 — Useful DAX Functions Quick List
Math & Stats
ROUND(x, 2) · ROUNDUP(x, 0) · ROUNDDOWN(x, 0) · INT(x)
ABS(x) · SQRT(x) · POWER(x, 2) · MOD(x, 2)
STDEV.P(col) · STDEV.S(col) · VAR.P(col) · MEDIAN(col)
PERCENTILE.INC(col, 0.75)
Text
CONCATENATE(a, b) · a & " " & b · LEFT(s, 3) · RIGHT(s, 4)
MID(s, 2, 4) · LEN(s) · UPPER(s) · LOWER(s)
TRIM(s) · SUBSTITUTE(s,"a","b") · FORMAT(1234.5, "#,##0.00")
FIND("@", s) · SEARCH("@", s) · VALUE("123") · UNICHAR/UNICODE
Date
YEAR(d) · MONTH(d) · DAY(d) · HOUR(t) · MINUTE(t) · SECOND(t)
DATE(2024,1,31) · TIME(14,30,0) · TODAY() · NOW() · UTCNOW()
DATEDIFF(d1, d2, DAY) -- DAY / MONTH / YEAR / HOUR / MINUTE / SECOND
WEEKDAY(d, 2) -- 1=Monday ... 7=Sunday
WEEKNUM(d) · EOMONTH(d, 0) · EDATE(d, -1) · DATEADD · DATESBETWEEN
Logical
IF(cond, trueVal, falseVal)
SWITCH(TRUE(), cond1, val1, cond2, val2, default)
IFERROR(expr, fallback) · ISBLANK(x) · COALESCE(a, b, c)
AND(a, b) · OR(a, b) · NOT(a) -- ya && || !
Table
SUMMARIZE(Table, Col1, Col2, "Name", [Measure])
SUMMARIZECOLUMNS(Col1, Col2, "Total", [Measure]) -- ⭐ best practice
ADDCOLUMNS(Table, "NewCol", expr)
SELECTCOLUMNS(Table, "A", Table[Col])
FILTER(Table, condition)
TOPN(5, Table, [Measure], DESC)
RANKX(ALL(Product[Name]), [Total Sales], , DESC, DENSE)
CROSSJOIN(t1, t2) · UNION(t1, t2) · EXCEPT(t1, t2)
VALUES(col) · DISTINCT(col) · COUNTROWS(t)
GENERATE(t1, t2) · NATURALINNERJOIN(t1, t2)
SUMMARIZECOLUMNS — modern best practice ⭐
-- Report table banane ke liye (calculated table)
Sales Summary =
SUMMARIZECOLUMNS(
Product[Category],
DimDate[Month Year],
"Total Sales", [Total Sales],
"Orders", [Total Orders],
"OTD %", [OTD %]
)
RANKX — ranking in DAX ⭐
Sales Rank =
RANKX(ALL(Product[Product_Name]), [Total Sales], , DESC, DENSE)
Top 5 Products =
CALCULATETABLE(
VALUES(Product[Product_Name]),
TOPN(5, VALUES(Product[Product_Name]), [Total Sales], DESC)
)
🚫 PART 12 — Common DAX Mistakes (tumhare bhi the)
| ❌ Mistake | ✅ Fix |
|---|---|
calculate(total_sales, ...) — measure bina bracket | CALCULATE([Total Sales], ...) |
total sales (space wala naam bina bracket) | [Total Sales] |
Unbalanced parentheses ) | Editor ka red underline check karo |
DIVIDE(a, b) * 100 | DIVIDE(a, b, 0) + Percentage format |
AVERAGE(Sales[Amount]) for AOV | DIVIDE([Total Sales], [Total Orders]) |
| Time intelligence in calculated column | Measure me likho |
| Bina marked date table time intelligence | Date table mark karo |
FILTER() for simple comparison | Boolean expression use karo (fast) |
PREVIOUSYEAR on multi-year total | SAMEPERIODLASTYEAR / DATEADD |
| Hard-coded values in measure | VAR + parameters |
🎤 PART 13 — Interview One-Liners (DAX)
| Question | Answer |
|---|---|
| Row context vs Filter context? | Row context = current row (filter nahi karta), Filter context = allowed rows (filter karta hai). Row context relationships se propagate nahi hota. |
CALCULATE kya karta hai? | Filter context modify karta hai + context transition (row → filter) karta hai |
SUM vs SUMX? | SUM = column aggregate (fast), SUMX = row-by-row iterator |
ALL vs ALLEXCEPT vs ALLSELECTED? | ALL = sab hatao, ALLEXCEPT = specific rakho, ALLSELECTED = slicer rakho visual hatao |
FILTER vs Boolean in CALCULATE? | Simple comparison → Boolean (VertiPaq optimized). Complex row logic → FILTER |
RELATED vs RELATEDTABLE? | RELATED = many-to-one (single value), RELATEDTABLE = one-to-many (table) |
| Calculated column vs measure? | Column = stored/row context/slicer me use. Measure = dynamic/filter context/default choice |
VALUES vs SELECTEDVALUE? | VALUES = table, SELECTEDVALUE = single scalar |
| Time intelligence ke liye kya chahiye? | Marked date table with continuous dates + relationship |
PREVIOUSMONTH vs DATEADD? | PREVIOUSMONTH = full calendar month (sirf -1). DATEADD = same range shifted, koi bhi offset |
DIVIDE kyun? | Divide-by-zero handle karta hai + alternate result |
VAR/RETURN ka faayda? | Readability + performance (ek baar evaluate hota hai) |
| Star schema kyun? | Single fact + multiple dimensions = fast filtering, simple DAX, no ambiguity |
| Bi-directional relationship kab? | Rarely — performance aur ambiguity badhata hai. Default single direction |
✅ Revision Priority
Tier 1 — MUST (yeh 15 aana hi chahiye): SUM · COUNTROWS · DISTINCTCOUNT · DIVIDE(a,b,0) · CALCULATE · AVERAGE trap · PREVIOUSMONTH · DATEADD · TOTALYTD · SAMEPERIODLASTYEAR · MoM/YoY growth · ALL() for % of total · VAR/RETURN · IF · Percentage format rule
Tier 2 — Strong impression: DATESINPERIOD (rolling) · SUMX · RELATED/RELATEDTABLE · ALLSELECTED · SWITCH(TRUE()) · RANKX · SUMMARIZECOLUMNS · SELECTEDVALUE · REMOVEFILTERS+VALUES
Tier 3 — Differentiator: Context transition explain karna · KEEPFILTERS · EARLIER · DATESBETWEEN · Star schema justification · ALLEXCEPT ki limitation · Measure branching · Field parameters
🏗️ Bonus — Star Schema Template
DimDate ──┐
│
DimProduct ──► FACT: Sales ◄── DimCustomer
│
DimWarehouse ─┘
Fact table: numeric measures + foreign keys (date, product, customer, warehouse)
Dim tables: descriptive attributes
Interview me yeh bolo: "Main hamesha star schema use karta hoon — ek fact table aur connected dimension tables. Isse DAX simple rehta hai, relationships unambiguous hoti hain, aur VertiPaq engine fastest scan kar pata hai."
Syntax Microsoft Learn + SQLBI documentation se verify kiya gaya hai. DAX sandbox me execute nahi hua.
Power BI DAX Cheat Sheet — Complete!
DAX syntax Microsoft Learn aur SQLBI documentation se verify ki gayi hai. Jahan behaviour subtle hai wahan doc reference diya gaya hai — honest marking, guess nahi.
Happy Learning & Keep Exploring! 🚀
💬 Comments (0)
Loading comments...