Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
vanessafvg
Super User
Super User

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?





If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!




1 ACCEPTED SOLUTION
geeb
Regular Visitor

4 REPLIES 4
geeb
Regular Visitor

Here's a good blog post on CALCULATE and how it works.

 

http://sqlblog.com/blogs/marco_russo/archive/2010/01/03/how-calculate-works-in-dax.aspx

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?





If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.