Implicit Context Transition

Until today I used to think only CALCULATE and CALCULATETABLE can do context transition but after a post by @michellepace I searched on Dax Guide and other places and I found that some other function implicitly and internally call CALCULATETABLE for context transition.

Some of these functions are SAMEPERIODLASTYEAR, LASTDATE, FIRSTDATE, RELATEDTABLE, DATEADD, all the NEXT/PREVIOUS/START/END function family, internally they call CALCULATETABLE ( DISTINCT ( Dates[Date] ) )

example: LASTDATE ( CALCULATETABLE ( DISTINCT ( Dates[Date] ) ) )

I never knew about this because as far as I can remember I have never used these functions in a row context except RELATEDTABLE and can’t actually think of a reason for using some of them in a row context.

Most shocking one is RELATEDTABLE, I used to think it follows the relationship and searches for the matching rows on many side that are related to one side, but it looks like after thinking in terms of context transition it makes more sense, in short it is just like CALCULATETABLE ( TableName ) with no additional arguments.

Just wanted to point out that always refer to https://dax.guide/ before writing a code otherwise something that works today might break tomorrow. I was foolish enough to not refer it as rigorously as I should have until today, but that’s a new learning for me :slight_smile:

4 Likes

Marking the post as closed.

@AntrikshSharma

Pal you have put in some real thought. I really like it. Keep up this "DAX"ing spirit young and eventful.

Best Regards,
Hemant

2 Likes

@AntrikshSharma,

I would also suggest using the knowledge base, or DAX Function Guide on the Enterprise DNA website as a resource before writing your DAX.

Thanks
Jarrett