Ravindra BagaleCourses & study guides Track your progress

Labs · Power BI

Lab: Write Your First CALCULATE Measure – Total Sales for Mumbai Only

Beginner30 minPower BI Desktop (free) · Your Lab C file

Course: Power BI · Chapter 13: DAX: Data Analysis Expressions

Chapter 13 teaches DAX; this lab is your first CALCULATE.

Download city_sales.csv (12 rows)

Chala mitrano! CALCULATE is the most important DAX function, and many students fear it. Today we use it for one small job: total sales for Mumbai only. First we see the data before and after with our own eyes, then the formula, then the clicks. Ghabru naka, it is just one line.

Suppose we are…

Suppose we are still the junior analyst at Flipkart from Lab C. Now the Mumbai regional head asks for one number on her page: "Mumbai sales". It must stay Mumbai even when someone clicks Pune or Nagpur on another chart of the report. A normal chart sum changes with every click, so we need a measure (a saved DAX formula that calculates a number whenever a visual needs it) that always applies the Mumbai filter itself.

As in Lab C, the numbers are sample data made up for practice, not real Flipkart figures.

Goal of this lab

By the end you will have:

  • Written a base measure Total Sales with SUM.
  • Written your first CALCULATE measure, Mumbai Sales.
  • Shown it in a Card and in two Tables, and explained why it shows 147,000 on every city row.

What you need (all free)

  • Power BI Desktop on Windows (free, Microsoft Store).
  • Your file Lab-C-city-sales.pbix from Lab C. No file yet? Do Lab C first (30 minutes), or load the same sample: Download city_sales.csv (12 rows)
  • 30 minutes.

The data: before and after

Before. These are the same 12 rows as Lab C. The 4 Mumbai rows are highlighted.

Before: 12 rows of city_sales with the 4 Mumbai rows highlighted, adding up to 147,000

After. Our new measure Mumbai Sales gives 147,000 in a Card:

After: a Card visual showing 147K Mumbai Sales

In a table by Product, it shows only the Mumbai part of each product, next to the all-city total:

After: Mobile 176,000 total and 78,000 Mumbai; Laptop 163,000 and 61,000; Headphones 26,000 and 8,000; total 365,000 and 147,000

In a table by City, it shows 147,000 on every row, even on Pune and Nagpur:

After: by City, Total Sales changes per row but Mumbai Sales stays 147,000 on every row

The formula

We write two measures. The first adds up the Sales column:

Total Sales = SUM ( city_sales[Sales] )

city_sales is the table name (Power BI took it from the file name), and [Sales] is the column inside it.

The second one reuses the first, but with a filter:

Mumbai Sales = CALCULATE ( [Total Sales], city_sales[City] = "Mumbai" )

Read it like a sentence: "Calculate Total Sales, but first keep only the rows where City is Mumbai." CALCULATE takes two things:

  1. What to calculate: [Total Sales].
  2. Which filter to apply first: city_sales[City] = "Mumbai". Text always goes inside double quotes.

Why is it 147,000 on the Pune row of the city table? Each row of a visual sends its own filter to the measure (this is called filter context: the filters coming from the row, slicers and clicks). On the Pune row, the filter is City = Pune. CALCULATE replaces the City filter with City = Mumbai, so the answer is Mumbai's total. On the product table, the row filter is on Product, not City, so CALCULATE keeps it and adds City = Mumbai: Mobile in Mumbai = 42,000 + 36,000 = 78,000.

Steps

  1. Open Lab-C-city-sales.pbix in Power BI Desktop (File → Open report → Browse reports).
  2. In the Data pane on the right, right-click the table city_sales and choose New measure.

    What you should see: a formula bar above the canvas with the text Measure =.

  3. Select all the text in the formula bar, type Total Sales = SUM ( city_sales[Sales] ) and press Enter.

    What you should see: Total Sales in the Data pane under city_sales, with a small calculator icon.

  4. Right-click city_sales again and choose New measure.

  5. Type Mumbai Sales = CALCULATE ( [Total Sales], city_sales[City] = "Mumbai" ) and press Enter.
  6. Click an empty part of the canvas so that no visual is selected.
  7. In the Visualizations pane, click the Card icon. Drag Mumbai Sales into the card's field box (called Fields or Data, depending on your Power BI version).

    What you should see: the card shows 147K and the label Mumbai Sales.

  8. Click an empty part of the canvas again, click the Table icon in Visualizations, and drag Product, Total Sales and Mumbai Sales into its Columns box.

    What you should see: Mobile 176,000 and 78,000, Laptop 163,000 and 61,000, Headphones 26,000 and 8,000, and a total row of 365,000 and 147,000.

  9. Make a second table with City, Total Sales and Mumbai Sales.

    What you should see: Total Sales changes per city (147,000, 131,000, 87,000), but Mumbai Sales is 147,000 on every row.

  10. Now click the Pune bar in your Lab C bar chart.

    What you should see: the product table's Total Sales changes to Pune's numbers, but the card still shows 147K. Click the Pune bar again to clear the selection.

  11. Click File → Save as and save the file as Lab-D-calculate-mumbai.

Ravindra Bagale's Tip

Many students write 'Mumbai' in single quotes, the way Excel users sometimes do. In DAX, single quotes are for table names, so you get an error. Text values go in double quotes: "Mumbai". And if the card shows (Blank), check the spelling of the city. Dhyan rakho!

Common mistakes

Mistake What happens Fix
'Mumbai' in single quotes Error: DAX reads it as a table name Use double quotes: "Mumbai"
Clicked New column instead of New measure You get a column with a value on every row, not one number Delete it (right-click → Delete from model) and use New measure
Spelling "Mumbia" or "Mumbai " with a space The card shows (Blank) because no row matches Copy the city name exactly as it is in the data
Typing the table name wrong, for example sales[Sales] Error: cannot find table Use the name shown in the Data pane: city_sales
Using SUM ( city_​sales[City] ) Error: SUM needs a number column SUM the Sales column
Expecting Mumbai Sales to change when you click Pune It stays 147K and you think it is broken That is the point of CALCULATE: it replaces the City filter

Self-check checklist

0 of 6 done

Try-at-home challenge

Write these two measures yourself, then check your answers:

  1. Pune Laptop Sales: total sales for Pune and Laptop only. Hint: CALCULATE can take more than one filter, separated by a comma.
  2. Mumbai Share %: Mumbai Sales as a percentage of Total Sales. Hint: use DIVIDE and set the format to Percentage on the Measure tools ribbon.
Check your answers
Pune Laptop Sales = CALCULATE ( [Total Sales], city_sales[City] = "Pune", city_sales[Product] = "Laptop" )
Mumbai Share % = DIVIDE ( [Mumbai Sales], [Total Sales] )

Pune Laptop Sales = 55,000 (one row: 2026-01-05). Mumbai Share % = 147,000 ÷ 365,000 = 40.27% in a card with no filters.

Samjla ka? CALCULATE = what to calculate + which filter to apply first. Aata pudhe jaauya: the next DAX labs build on this with ALL, FILTER and time intelligence.