Back to all posts

Calculate and Calculatetable Function in Power BI

CALCULATE : It's used to modify or filter the context in which a calculation is being performed CALCULATE(<expression>, <filter1>, <filter2&…

CALCULATE: It's used to modify or filter the context in which a calculation is being performed

Bash
CALCULATE(<expression>, <filter1>, <filter2>, ...)

TotalSales = CALCULATE(SUM(Sales&#091;Amount]), Sales&#091;Region] = "North")

-- select sum(Amount) from Sales where Region = 'North'
Python
Customer Sales Measure (store id) = 
CALCULATE(
    SUMX(
        'Sales by Store',
        'Sales by Store'&#091;quantity_sold] * 'Sales by Store'&#091;unit_price]
    ),
    'Sales by Store'&#091;store_id] = 8
)

-- or  

Customer Sales messaure (store id) = 
SUMX(
    FILTER('Sales by Store','Sales by Store'&#091;store_id]==8),
    'Sales by Store'&#091;quantity_sold] * 'Sales by Store'&#091;unit_price]
)

CALCULATETABLE: It is similar to CALCULATE but specifically designed for table expressions. This function is particularly useful when you want to apply filters to a table and return a new table based on those filters.

HTML
CALCULATETABLE(<table>, <filter1>, <filter2>, ...)
CSS
Sales Table:

SaleID	ProductCategory	Amount
1	Electronics	100
2	Furniture	200
3	Electronics	150
4	Clothing	300
Bash
ElectronicsSales = 
CALCULATETABLE(
    Sales,
    Sales&#091;ProductCategory] = "Electronics"
)
Plain Text
SaleID	ProductCategory	Amount
1	Electronics	100
3	Electronics	150

Keep building your data skillset

Explore more SQL, Python, analytics, and engineering tutorials.