CALCULATE
function modifies the filter context to include all products for that month by using the ALL
function.
If we want to calculate the total revenue for a specific product over all months. We can use the following DAX formula:
CALCULATE
function to filter the rows where the product is “Product A”. The function creates a filter context where only the rows with “Product A” are included, and then calculates the sum of revenue for those rows.
Suppose we have a table named “Employees” with columns “Employee Name”, “Department”, and “Salary”. We want to add a calculated column that will rank employees by salary within each department. We can use the following DAX formula:
FILTER
function creates a filter context where only the rows with the same department as the current row are included, and the EARLIER
function is used to reference the department value of the current row. The RANKX
function then computes the rank of the current row’s salary within the filtered rows.
If we want to calculate the average salary for employees in a specific department.
CALCULATE
function to filter the rows where the department is “Sales”. The function creates a filter context where only the rows with “Sales” are included, and then calculates the average salary for those rows.
FILTER
function creates a new filter context by filtering the rows where the Product column is “Product A” and the Year column is 2023. The expression then evaluates in the context of the filtered rows and calculates the total sales amount for the specified product and year.
CALCULATE
function is used in the filter context, while the SUMX
function is used in the row context.