cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
vanessafvg
Super User I
Super User I

is it best practice to put calculate in front of every measure?

In dax when you created a calculated measure, should one always put calculate in front of it?  Just trying to understand the benefit?





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




1 ACCEPTED SOLUTION
geeb
Regular Visitor

4 REPLIES 4
geeb
Regular Visitor

bblais
Resolver III
Resolver III

I would only use CALCULATE if I have a filter to apply when performing an aggregation.  For example, if I'm creating a "Revenue" measure that's a simple sum of sales from my sales table, I would just use:

 

Revenue = SUM(Sales[Sales])

I typically create these basic measures like this all the time and never just use the field out of the sales table, even though visuals can handle it.  But let's say I wanted a special measure called "East Region Revenue", then I would use the CALCULATE function to apply a filter:

 

East Region Revenue = CALCULATE([Revenue], Region[Region Name] = "East")

The above assumes I have an active relationship between my sales table and region table.

thanks for the response, can i just ask only why when you have a filter?   so in other words you are using this instead of the filter function?





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




FILTER returns a table filtered by whatever you filter it by.  CALCULATE keeps the context of all filters already applied except for the filter you apply in the CALCULATE itself, and then performs whatever expression you are calculating.  So in my example, if I had a visual that was filtering by some other slice, say product, that filter would stay intact, but any filters in my visual on [Region Name] would be ignored in lieue of the specific filter I set in the CALCULATE call.  You can actually use FILTER inside CALCULATE to specify one of the filters to use if necessary as well.

Helpful resources

Announcements
MBAS on Demand

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

July 2021 Update 768x460.png

Check it out!

Click here to read more about the July 2021 Updates

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

Top Solution Authors
Top Kudoed Authors