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
abbytank
Frequent Visitor

Dax Calculate Function

I have been wrestling to understand how logically the following to statements or (measures) are providing different results. 

 

Sales PCT_1 =

    var current_sales = sumx(sales, Sales[Quantity]*Sales[Net Price])

    var all_sales = calculate(current_sales,all('Product Category'[Category]))

    var pct_ratio = DIVIDE(current_sales,all_sales,0)

    return pct_ratio

 

Sales PCT_2 =

    var current_sales = sumx(sales, Sales[Quantity]*Sales[Net Price])

    var all_sales = calculate(sumx(sales, Sales[Quantity]*Sales[Net Price]),all('Product Category'[Category]))

    var pct_ratio = DIVIDE(current_sales,all_sales,0)

    return pct_ratio

(the first one provides all results 100% and ingnores all filters even while the later one provides better results when I categorise the result)

I would be gratefull if someone help me how using the statement or the variable have made the changes.

 

Thanks in advance.

1 ACCEPTED SOLUTION
MattAllington
Community Champion
Community Champion

Variables are not variable, they are constant.

 

You cannot alter the value of a variable once it has been assigned. Therefore this line of code does not change the value of the variable

var all_sales = calculate(current_sales,all('Product Category'[Category]))



* Matt is an 8 times Microsoft MVP (Power BI) and author of the Power BI Book Supercharge Power BI.
I will not give you bad advice, even if you unknowingly ask for it.

View solution in original post

1 REPLY 1
MattAllington
Community Champion
Community Champion

Variables are not variable, they are constant.

 

You cannot alter the value of a variable once it has been assigned. Therefore this line of code does not change the value of the variable

var all_sales = calculate(current_sales,all('Product Category'[Category]))



* Matt is an 8 times Microsoft MVP (Power BI) and author of the Power BI Book Supercharge Power BI.
I will not give you bad advice, even if you unknowingly ask for it.

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!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.