← Back to Modules 🏠 Back to Home
Created by Gagan Sir
Module 05: CALCULATE, FILTER, Context Transition & Variables
Power BI Desktop + Power Query + Data Modeling + DAX Formulas + Time Intelligence + Visual Selection + 50+ Interview Q&A
13
CALCULATE and FILTER Mechanics
🇬🇧 English Definition
CALCULATE is the most powerful function in DAX. It evaluates an expression in a modified filter context. FILTER returns a table of matching rows and is passed into CALCULATE for complex filters.
🇮🇳 Hinglish Definition
CALCULATE existing filter context ko change ya override karke formula calculate karta hai. FILTER function condition matching rows ki table return karta hai.
// CALCULATE Simple Filter Modification Mohali Sales = CALCULATE([Total Sales], Sales[City] = "Mohali") // Expected Output: ₹1,30,000 // CALCULATE with FILTER Function High Value Sales = CALCULATE([Total Sales], FILTER(Sales, Sales[Sales] > 10000))
14
Filter Modifiers & Sales Share %
FunctionPurpose / Kaam
CALCULATEEvaluate expression in modified filter context
FILTERReturn table matching logical condition
ALLClear all filters from table or column
REMOVEFILTERSExplicitly clear filters from specified table/column
ALLEXCEPTClear all filters except specified columns
KEEPFILTERSIntersect new filter with existing filter context
ALLSELECTEDRespect visual slicers while ignoring row grouping filters
// Sales Share % (City Contribution to Total Sales) Sales Share % = DIVIDE([Total Sales], CALCULATE([Total Sales], REMOVEFILTERS(Sales[City])), 0)
🔍 REMOVEFILTERS Behavior
  • `REMOVEFILTERS(Sales[City])` clears the City filter to compute total company sales while preserving Date or Product slicer selections!
  • 15
    Row Context vs Filter Context vs Context Transition
    ConceptExampleExplanation
    Row contextProfit = Sales[Sales] - Sales[Cost]Knows current row values automatically during iteration
    Filter contextTotal Sales = SUM(Sales[Sales])Active slicers, report filters, and visual rows filtering data
    Context transitionCALCULATE() inside row contextConverts current row context into equivalent filter context
    City Filter Context Breakdown Table
    Selection / CityTotal Sales Output
    No city filter (Overall)₹2,87,000
    Mohali₹1,30,000
    Chandigarh₹97,500
    Ludhiana₹54,500
    Ropar₹5,000
    16
    VAR and RETURN & Virtual Tables
    // Variables for readability & performance Profit Margin % = VAR Revenue = [Total Sales] VAR ProfitValue = [Total Profit] RETURN DIVIDE(ProfitValue, Revenue, 0)
    Virtual Table FunctionPurpose / Kaam
    VALUES / DISTINCTReturn distinct single-column table
    ADDCOLUMNSAdd calculated columns to a table expression
    SUMMARIZECreate a grouped summary table (like SQL GROUP BY)
    SELECTCOLUMNSReturn selected or renamed columns
    TOPNReturn top N rows based on expression
    CROSSJOINCreate Cartesian product combinations between tables
    UNION / INTERSECT / EXCEPTCombine or compare table rows
    Product Summary = SUMMARIZE(Sales, Sales[Product], "Product Sales", SUM(Sales[Sales]))