Power Query vs DAX — What Goes Where in Power BI
Power Query (M) cleans and reshapes tables before they load into the model. DAX calculates measures and columns inside the model. Shape early in Query. Analyse with filter-aware DAX.
Friends! Students try to unpivot with DAX and write year-to-date with Replace Values. That pain is optional. Today we draw a hard line: what goes in Power Query, what goes in DAX, and a decision test you can reuse forever.
मित्रांनो! Students try to unpivot with DAX and write year-to-date with Replace Values. That pain is optional. Today we draw a hard line: what goes in Power Query, what goes in DAX, and a decision test you can reuse forever.
मित्रों! Students try to unpivot with DAX and write year-to-date with Replace Values. That pain is optional. Today we draw a hard line: what goes in Power Query, what goes in DAX, and a decision test you can reuse forever.
Quick answer
Placement rules (vertical):
- Remove junk rows, fix types, rename columns, split, merge, unpivot → Power Query.
- KPI totals, ratios, “sales for selected year”, time intelligence → DAX measures.
- Row labels/flags needed as fields → calculated column (still DAX) after the table is clean.
- Do not rebuild the same Year column in both places without a reason.
- Pipeline: Source → Query → Model → DAX visuals.
Power Query = prepare tables
DAX = calculate answers under filters
What do I need before this guide?
- You have loaded at least one table (Excel/CSV).
- You know measures vs columns at a basic level (guide).
- Course: What is Power Query?.
Before and after (look at the tables first)
Before
आधी (Before)
पहले (Before)
After
नंतर (After)
बाद में (After)
Power Query reshapes before the model (here drop 2024 → 140). DAX then measures what is left under slicers.
Why placement matters (and why you care)
Wrong layer = slow refresh, wrong numbers, or impossible maintenance.
Why you care:
- Unpivoting 36 month columns with DAX iterators is swimming upstream.
- Calculating “selected year sales” only with a static Query filter fights interactive reports.
- Clean Query + clear measures is how teams hand over
.pbixfiles without drama.
Tiny story:
- Raw file has Mumbai 100 and Pune 40, but Amount is text and City has trailing spaces.
- Fix that in Power Query.
- Then write
Total Sales = SUM ( Sales[Amount] )in DAX so a slicer can show Mumbai 100.
Power Query (M) cleans and reshapes before the model; DAX calculates measures and columns inside the model.
मित्रांनो — Power Query (M) cleans and reshapes before the model; DAX calculates measures and columns inside the model.
मित्रों — Power Query (M) cleans and reshapes before the model; DAX calculates measures and columns inside the model.
Power Query responsibilities (with examples)
Pipeline: Source → Power Query → Model → DAX / visuals. Shape first, then analyse.
मित्रांनो — Pipeline: Source → Power Query → Model → DAX / visuals. Shape first, then analyse.
मित्रों — Pipeline: Source → Power Query → Model → DAX / visuals. Shape first, then analyse.
What Power Query is
Power Query is the Transform data window. It cleans and reshapes tables before they enter the model. Each click becomes an Applied Step. Refresh replays those steps.
Why use Power Query
- The file shape is wrong (titles, junk rows, wide month columns).
- Types are wrong (Amount as text).
- You need the same clean table every refresh.
What to do there (vertical list)
- Promote headers and rename columns to clear business names.
- Set data types (Decimal, Date, Text).
- Filter out total rows, blank order IDs, test cities.
- Split “City|State” into two columns.
- Merge queries (lookup Region from a Cities table).
- Unpivot month columns into Date + Amount rows.
- Append monthly CSV files (Folder pattern — course chapter).
Tiny example — what happens to the rows
- Start: one messy row shows City =
"Mumbai "and Amount ="100"(text). - Trim City →
"Mumbai". - Set Amount type → number 100.
- Same for Pune 40.
- Close & Apply — the model now has clean numbers ready for SUM.
What you see on screen: Applied Steps on the right (Source, Changed Type, …) and a clean preview grid.
DAX responsibilities (with examples)
What DAX is here
DAX is the formula language inside the model. After Close & Apply, you write measures (and sometimes columns) that answer business questions under filters.
Why use DAX (not Query) for KPIs
- The answer must change when the reader clicks Mumbai.
- You need ratios, “sales in 2025”, or comparisons.
- Query filters at refresh are static — they do not replace interactive measures.
What to do after Close & Apply (vertical list)
Total Sales = SUM ( Sales[Amount] )→ overall 140 for Mumbai 100 + Pune 40.Orders = DISTINCTCOUNT ( Sales[OrderId] ).Sales 2025 = CALCULATE ( [Total Sales], Date[Year] = 2025 )(with a Date table).- Margins and ratios that must respond to slicers.
- Dynamic titles and advanced patterns later in the course.
DAX sees the model — relationships, filter context, measures calling measures.
Decision aid: fix columns and types in Power Query; build filter-aware totals as DAX measures.
मित्रांनो — Decision aid: fix columns and types in Power Query; build filter-aware totals as DAX measures.
मित्रों — Decision aid: fix columns and types in Power Query; build filter-aware totals as DAX measures.
Decision test (use every time)
Ask one sentence: “Must this change when the reader clicks a slicer?”
- No — it is about the shape of the raw file → Power Query.
- Yes — it is an analytical answer → DAX measure.
- It is a row attribute I will group/filter on → clean in Query if possible; else calculated column.
Worked micro-examples
- Replace
N/Awith null in Amount → Query. - Show sales for the cities currently selected (Mumbai → 100) → Measure.
- Create Year from OrderDate for a relationship to Date → preferably Query (or a proper Date table strategy in modelling).
- Year-to-date sales → DAX (after Date table exists).
- Unpivot Jan–Dec columns → Query.
What beginners should not do
- Load dirty sheets “as is” and patch everything with DAX.
- Create dozens of calculated columns that copy Query logic.
- Filter the whole fact table in Query to one year, then wonder why the year slicer is empty.
- Fear Power Query because the formula bar shows M — you can do 80% from the ribbon.
Performance intuition (beginner level)
- Query work runs at refresh.
- Measure work runs when visuals query.
- Heavy row-by-row DAX over huge fact tables can feel slow — keep preparation in Query when it is really preparation.
Ravindra Bagale's Tip
A common mistake: students open DAX to rename columns. Rename in Power Query. Keep DAX for thinking with filters. Interviewers love that discipline. Remember this!
Ravindra Bagale's Tip – मराठी
एक common चूक: students columns rename करण्यासाठी DAX उघडतात. Rename Power Query मध्ये करा. DAX filters सोबत विचार करण्यासाठी ठेवा. Interviewers ला ती discipline आवडते. हे लक्षात ठेवा!
Ravindra Bagale's Tip – हिंदी
एक common गलती: students columns rename करने के लिए DAX खोलते हैं. Rename Power Query में करो. DAX filters के साथ सोचने के लिए रखो. Interviewers को वो discipline पसंद है. ये याद रखो!
Practice task
Take any messy CSV (include Mumbai 100 and Pune 40):
- List five fixes → mark each Query or DAX.
- Implement the Query fixes; Close & Apply.
- Create two measures only.
- Screenshot Applied Steps + Fields measures for your notes.
Decision workshop (copy into Notes)
For each task, write Q or D:
- Trim spaces in City → Q
- Sales YTD → D
- Merge Region from Cities.xlsx → Q
- % of total sales → D
- Unpivot month columns → Q
- Distinct order count → D
- Replace “NA” with null → Q
- Same-period last year → D (after Date table)
If you marked any of 1/3/5/7 as D, revisit this guide.
Refresh mental model
- Click Refresh in Desktop → Query steps run → model tables update → visuals query measures.
- Confusing Query with DAX usually means confusing refresh time with interaction time.
Tiny check: after refresh, Mumbai is still 100, Pune still 40, and [Total Sales] still returns 140 until a slicer narrows it.
End-to-end mini project (45 minutes)
- Create a wide Excel with columns: City, Jan, Feb, Mar (Mumbai Jan 100, Pune Jan 40).
- Get data → Excel → Transform.
- Select Jan–Mar → Unpivot Columns → rename Attribute to Month, Value to Amount.
- Set types; Close & Apply.
- Create
[Total Sales] = SUM ( Sales[Amount] )in DAX. - Visualise City vs Amount.
- Notice: unpivot was Query; total was DAX — that is the whole lesson in one file.
M language fear reduction
- Every ribbon click writes M in Applied Steps.
- You can ignore M syntax for weeks and still ship clean tables.
- Peek at the formula bar later out of curiosity — not on day one.
Got it? Query prepares; DAX answers under filters. Use the slicer question as your compass. Next: DAX beginner tour. Let’s continue.
समजलं का? Query prepares; DAX answers under filters. Use the slicer question as your compass. Next: DAX beginner tour. आता पुढे जाऊया.
समझ में आया? Query prepares; DAX answers under filters. Use the slicer question as your compass. Next: DAX beginner tour. आगे बढ़ते हैं.
Frequently asked questions
What is Power Query?
The transform engine (M language) behind Transform data — it shapes tables before they load into the model.
What is DAX?
Data Analysis Expressions — formulas inside the model for measures, calculated columns and calculated tables.
Unpivot in DAX or Query?
Unpivot in Power Query. DAX is a poor place to reshape wide month columns.
Year-to-date total?
DAX measure (time intelligence), after you have a proper Date table.
Replace values “N/A” with blank?
Power Query Replace Values / conditional column — keep the model clean.
Course links?
Power Query essentials and DAX introduction chapters linked at the end.