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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
mkeisha
Helper I
Helper I

What is CALCULATE doing in this simple measure?

I created the following measure that actually does what I intended it to do but I don't understand what "calculate" is doing. Here's the measure:

Total Qty of Line Items = SUMX(VALUES(SALES[OrderNumber]), CALCULATE([Line MAX]))

It is correctly providing the total number of line items. The VALUES(SALES[OrderNumber] creates a virtual table of unique order numbers (because my sales table had duplicate order numbers) and then Line MAX refers to the number of line items within each order. But why do we need the CALCULATE in the measure before the SUMX goes ahead and adds up all the line items? I think it has to do with context transition but isn't this measure already in a row context? 

Thank you.

1 ACCEPTED SOLUTION

Hi @mkeisha ,

Based on my test using your sample data, it will return the same result whether using Calculate() function.

Snipaste_2019-04-23_13-56-11.pngSnipaste_2019-04-23_13-56-27.png

Actually, they should return the same result.

Best Regards,

Teige

View solution in original post

5 REPLIES 5
mkeisha
Helper I
Helper I

Hi thanks for your reply.  Here are all the measures:Capture.JPGHere's the  Sales1 table (just a few rows with sample data):

Capture2.JPG

 

And here's the pivot table output with the [Total Lines] measure using CALCULATE correctly.

Capture3.JPG

 

 

 Appreciate your help.

In your Line Total measure you don't need a CALCULATE, since you are already using a measure [Line Max]. All measures has an implicit calculate wraped around it.

But, it is not a good practice to do Context Transition over a high granular column like Order Number. It tend to take up lot of memory as the number of rows in your Datamodel increase, and can slow down the report. Why can't you just use:

Total Lines = COUNTROWS(SALES1)

If the granularity of Table is going further below Line, then it may not work. In addition, in your example dataset, if user filter for Order Date: 9/29/2003, you will get Total Lines as 2. But it should be 1 though right? If the requirement is to see 2 in such case, then your approach maybe correct.

Hi @mkeisha ,

Based on my test using your sample data, it will return the same result whether using Calculate() function.

Snipaste_2019-04-23_13-56-11.pngSnipaste_2019-04-23_13-56-27.png

Actually, they should return the same result.

Best Regards,

Teige

TeigeGao
Solution Sage
Solution Sage

Hi @mkeisha ,

Based on my test, the CALCULATE() function in the SUMX() function will not affect the result because SUMX() function has created the context. Generally, we will use CALCULATE() function to change the context.

If in your scenario, only CALCULATE() can work, could you please share some sample data and the measure [Line MAX] to help us analysis this problem.

Best Regards,

Teige

ChrisMendoza
Resident Rockstar
Resident Rockstar

@mkeisha -

 

I am definitely not qualified to explain this however, this may be useful to you https://www.sqlbi.com/articles/understanding-context-transition/.






Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

Proud to be a Super User!



Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.