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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Drakorv
New Member

DAX Logic for Measures

Hi everyone, I have a little question that I'm not sure why the formulas work like this. I have a measure that calculates Stock (In - Out). Here are the measures:

 
 
Stock Historico = CALCULATE([Stock];FILTER(ALL(Calendario);Calendario[Date]<=MAX(Calendario[Date])))
Stock Historico2 = CALCULATE([Stock];FILTER(ALL(Calendario);Calendario[Date]<=[Max]))
Max = MAX(Calendario[Date])
 
 
Drakorv_1-1619445892221.png

 

Both measures "in theory" do the same, but they work differently. I'm not totally sure why. When I use the "Max date" previously defined in another measure [Max], it is affected by the ALL filter I have, but when I use the base formula MAX([Date]) in the calc, it isn't. Do you know why?
 
Thank you very much in advance
1 ACCEPTED SOLUTION
Fowmy
Super User
Super User

@Drakorv 

In your 2nd Measure, you are using a measure named [Max]. Measures are always wrapped within the calculate function. This way, it always calculates the Maximum date overwriting the date column value.

In your 1st measure, MAX(Calendario[Date]) takes the outer row context from the visual on the date where no context transition happens.

Hope that made it clear.

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

View solution in original post

2 REPLIES 2
Jihwan_Kim
Super User
Super User

Hi, @Drakorv 

I am not sure about how your other measures look like, but I think,

the first measure -> it creates something like cumulate-total-pattern. because max(date) is inside the measure.

the second measure -> it calculates [stock] measure for all dates. because max(date) is coming from the outside of the measure and it is already defined as one date, which is the last date of all date table.  And all date that is less than or equal to max(date) is same as all date table.

 

I hope I explained well.

 

Hi, My name is Jihwan Kim.

 

If this post helps, then please consider accept it as the solution to help other members find it faster, and give a big thumbs up.

 

Linkedin: linkedin.com/in/jihwankim1975/

Twitter: twitter.com/Jihwan_JHKIM

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Visit my LinkedIn page by clicking here.


Schedule a meeting with me to discuss further by clicking here.

Fowmy
Super User
Super User

@Drakorv 

In your 2nd Measure, you are using a measure named [Max]. Measures are always wrapped within the calculate function. This way, it always calculates the Maximum date overwriting the date column value.

In your 1st measure, MAX(Calendario[Date]) takes the outer row context from the visual on the date where no context transition happens.

Hope that made it clear.

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.