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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Applicable88
Impactful Individual
Impactful Individual

Question regarding syntac/ context transition cumulative sum

Hello,

I have a misunderstanding regarding the max within a cumulative sum/range sum:

RangeSum = [SumOfTotalAmount] -calculate(sum(Table1[Amount]), filter(allselected(Table1), Table1[Date].[Date] <= max(Tabl1[Date])))
 
First of all the function works properly, but regarding the last filter par:
Table1[Date].[Date] <= max(Table1[Date])))
Shouldn'T the max ()-function return the max date of all available rows of the whole table? Instead it rightfully display all the dates smaller or equal of the Date we look at, on that specific row. Since its a scalar function an there is no wrapping inside a Calculate function like calculate(max(Table1[Date])), how is a row context establish here? 
Also no X-aggregated function where use, so how it will no the row context?
 
I'm also asking because there might be some demands on other calculation where you want to compare to the MAX of something. That might be not the date. In that case you want it to compare to the MAX of the whole column. In this case how would I need to write it differently?
 
I hope I explained clear of what is my misunderstanding. 
Thank you very much in advanced.
Best regards. 
2 ACCEPTED SOLUTIONS
amitchandak
Super User
Super User

@Applicable88 , max(Table1[Date])  will take the row context , if need overall max try 

var _max = maxx(allselected(Table1), Table[Date]) // max of allselected

View solution in original post

v-angzheng-msft
Community Support
Community Support

Hi, @Applicable88 

 

I have an easy to understand explanation here, although it may not be completely correct. Glad to see different insights.
Max/Min/Sum functions are based on the row context, each row is a filtering condition, in the current row whether the maximum or minimum result is the current row, because the context is only one row?
So it will be seen in the column whether the Max function or Min function, the result is the value of the current row.
In the total, the context of the row is the whole table or rather all rows, so the result is correct in the total.
If you want to remove the limitation of the context, then you need to remove the filtering effect of the row context i.e. remove the filtering. 

vangzhengmsft_0-1626080708567.png

Then the DAX that correctly takes the maximum value could look like the following:

_realMaxDate = CALCULATE(MAX('Table'[Date]),ALL('Table'))

Hope this helps.

 

Best Regards,
Community Support Team _ Zeon Zheng
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
v-angzheng-msft
Community Support
Community Support

Hi, @Applicable88 

 

I have an easy to understand explanation here, although it may not be completely correct. Glad to see different insights.
Max/Min/Sum functions are based on the row context, each row is a filtering condition, in the current row whether the maximum or minimum result is the current row, because the context is only one row?
So it will be seen in the column whether the Max function or Min function, the result is the value of the current row.
In the total, the context of the row is the whole table or rather all rows, so the result is correct in the total.
If you want to remove the limitation of the context, then you need to remove the filtering effect of the row context i.e. remove the filtering. 

vangzhengmsft_0-1626080708567.png

Then the DAX that correctly takes the maximum value could look like the following:

_realMaxDate = CALCULATE(MAX('Table'[Date]),ALL('Table'))

Hope this helps.

 

Best Regards,
Community Support Team _ Zeon Zheng
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

amitchandak
Super User
Super User

@Applicable88 , max(Table1[Date])  will take the row context , if need overall max try 

var _max = maxx(allselected(Table1), Table[Date]) // max of allselected

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

April Fabric Community Update

Fabric Community Update - April 2024

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