cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
wribeiro
Frequent Visitor

Dax code - Differences

Hello everyone,

Could you help me? I wrote three ways to got the same value. I would like to know what is the difference between them, and what is the advantage to using them. Simple situation, just one fact table.

 

wribeiro_0-1670017014913.png

Base value:

Quantity = sum(Orders[Quantity])
 
1)
Big Quantities Calculate >30 =
CALCULATE([Quantity],
    Orders[Quantity]>30
    )
 
 
2)
Big Quantities sumX >30 =
sumx(
    filter(Orders,
    Orders[Quantity]>30
    ),Orders[Quantity]
)
 
3)
Big Quantities sumX Measure >30 =
sumx(
    filter(Orders,
    Orders[Quantity]>30
    ),[Quantity]
)
 
Thank you.

 

1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

@wribeiro No real difference between them, just different ways of doing the same thing. A lot of this is personal preference. There are many that are on the CALCULATE band wagon. I am not one of those people. I have a whole series of articles and videos on this topic. 

CALCUHATE - Why I Don't Use DAX's CALCULATE Functi... - Microsoft Power BI Community

https://www.youtube.com/playlist?list=PLoibEIc7heYNZbnY4CTCtg2tjEcMh8WbZ

 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

4 REPLIES 4
NanDeb
Helper I
Helper I

@Greg_Deckler interesting... 

When I first started on PowerBI, I was taught to use CALCULATE and still do but I am slowly moving away from it and preferring to iterate over a virtual table as it is easier to read..

 

Thanks for sharing your aricle

Greg_Deckler
Super User
Super User

@wribeiro No real difference between them, just different ways of doing the same thing. A lot of this is personal preference. There are many that are on the CALCULATE band wagon. I am not one of those people. I have a whole series of articles and videos on this topic. 

CALCUHATE - Why I Don't Use DAX's CALCULATE Functi... - Microsoft Power BI Community

https://www.youtube.com/playlist?list=PLoibEIc7heYNZbnY4CTCtg2tjEcMh8WbZ

 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...

Thank you @Greg_Deckler 

This seems like a simple question, but after years working with different BI tools and doing different type of calculations, I am looking for a reason to use calculate. I think it is the most useless function that I have seen if you want to creat a really useful semantic layer. without bias or hardcode.

 

Thank you for your clarification.

@wribeiro That kind of thinking will get you hate mail. Believe me, I know. I'm certain there is a use case out there somewhere but, yes, you are correct, CALCULATE is generally superfluous. But God forbid you actually say that. It does have the advantage of being able to "stack" your measures and calculate them in different contexts. However, I personally hate that approach as it makes debugging and troubleshooting and absolute nightmare.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Carousel_PBI_Wave1

2023 Release Wave 1 Plans

Power BI release plans for 2023 release wave 1 describes all new features releasing from April 2023 through September 2023.

Power BI Summit Carousel 2

Global Power BI Training

Make sure you register today for the Power BI Summit 2023. Don't miss all of the great sessions and speakers!

BizApps LATAM 2023

Business Application LATAM Summit 2023

Join the biggest FREE Business Applications Event in LATAM this February.

Power Platform Bootcamp

Global Power Platform Bootcamp

In this bootcamp we will deep-dive into Microsoft’s Power Platform stack with hands-on sessions and labs, delivered to you by experts and community leaders.

Top Solution Authors
Top Kudoed Authors