8. Adding Columns: Power Query Add Column Tab and DAX Calculated Columns
Practice and Answer Key: Calculated Columns vs Measures
Suppose we are checking discounts and delivery speed for the Blinkit Maharashtra team. Use src/practice/column_vs_measure_orders.csv (fictional practice data):
| Order ID | City | Amount (₹) | Discount (₹) | Delivery Time Mins | Order Status |
|---|---|---|---|---|---|
| 201 | Pune | 500 | 50 | 8 | Delivered |
| 202 | Nashik | 300 | 0 | 12 | Delivered |
| 203 | Pune | 700 | 100 | 9 | Delivered |
| 204 | Kolhapur | 400 | 0 | 18 | Delivered |
| 205 | Nashik | 0 | 0 | (null) | Cancelled |
About this data: This table uses columns: Order ID, City, Amount (₹), Discount (₹), Delivery Time Mins, Order Status. This table uses columns: City, Total Sales, Net Sales, Delivered, % Under 10 Mins, Discount % (measure), Average of Disc % (row). This table uses columns: What you see, Why, Fix. Values shown are the lesson examples already on this page (not a new dataset).
Exercise (one under the other):
- Load the CSV. In Power Query, Add Column › Conditional Column
Speed Band: if Delivery Time Mins equals null → "No delivery"; else if it is ≤ 10 → "Fast"; else "Slow". - Write measures
Total Sales,Net Sales(Amount minus Discount, row by row) andDelivered Orders. - Write
% Under 10 Mins= delivered orders with 10 minutes or less ÷ delivered orders. - Write
Discount %as a measure. Then make a calculated columnDisc % (row)and put its average next to it. - Build a matrix with Rows = City and compare.
Expected result (check your numbers):
| City | Total Sales | Net Sales | Delivered | % Under 10 Mins | Discount % (measure) | Average of Disc % (row) |
|---|---|---|---|---|---|---|
| Pune | ₹1,200 | ₹1,050 | 2 | 100% | 12.5% | 12.1% |
| Nashik | ₹300 | ₹300 | 1 | 0% | 0% | 0% |
| Kolhapur | ₹400 | ₹400 | 1 | 0% | 0% | 0% |
| Total | ₹1,900 | ₹1,750 | 4 | 50% | 7.9% | 6.1% |
Speed Band: 201 Fast, 202 Slow, 203 Fast, 204 Slow, 205 No delivery. Net Sales total = 1,900 − (50 + 100) = ₹1,750.
Answer key (open after you try)
Total Sales = SUM(Orders[Amount])
Net Sales = SUMX(Orders, Orders[Amount] - Orders[Discount])
Delivered Orders = CALCULATE(DISTINCTCOUNT(Orders[Order ID]), Orders[Order Status] = "Delivered")
% Under 10 Mins = DIVIDE(CALCULATE([Delivered Orders], Orders[Delivery Time Mins] <= 10), [Delivered Orders])
Discount % = DIVIDE(SUM(Orders[Discount]), SUM(Orders[Amount]))
-- calculated column (only to see the mistake)
Disc % (row) = DIVIDE(Orders[Discount], Orders[Amount])
Why 7.9% and 6.1% differ: the measure divides the totals (150 ÷ 1,900). The average of the row column gives every order the same weight: (10% + 0% + 14.3% + 0%) ÷ 4 = 6.1%. Order 205 is blank and is skipped. Ratios belong in measures.
Common mistakes:
| What you see | Why | Fix |
|---|---|---|
| Speed Band shows Error on order 205 | The null check comes after the ≤ 10 check | Put "equals null" as the first rule |
| Net Sales = ₹1,850 | Only the ₹50 discount was subtracted; order 203's ₹100 was missed | SUMX over all rows: 1,900 − (50 + 100) = 1,750 |
| Discount % total = 6.1% | Average of a row-level ratio column | Divide two sums in a measure |
| % Under 10 Mins = 40% | Cancelled order 205 counted in the bottom number | Divide by [Delivered Orders], not all orders |
Samajla ka? Row facts in columns, totals and ratios in measures.
Thodkyaat sangaycha tar (quick recap)
Fixed row-level columns go in Power Query; calculations that change with filters go in measures. Never average a ratio column. Keep measures numeric and use format settings. Now let us move on – combining many files from a folder.
Row-level fixed columns Power Query मध्ये, filter नुसार बदलणारे हिशोब measures मध्ये. Ratio कधीही column मध्ये average करू नका. Measures numeric ठेवा आणि format settings वापरा. आता पुढे जाऊया – folder मधून अनेक files एकत्र करूया.
Row-level fixed columns Power Query में, filter के साथ बदलने वाले हिसाब measures में. Ratio को कभी column में average मत कीजिए. Measures numeric रखिए और format settings इस्तेमाल कीजिए. अब आगे बढ़ते हैं – folder से कई files एक साथ जोड़ते हैं.