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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
CNENFRNL
Community Champion
Community Champion

Issue about CALCULATETABLE

Dear gurus,

I came across an issue which I can't wrap my head around; so I turn to you for help. Thnx in advance!

The senario is fairly simple, which involves only one simple table of dates. I use the date column as slicer; then I'd calculate all dates later than the selected date.

I authored a measures with CALCULATETABLE, which produces a wrong answer.

 

Wrong = 
VAR __date = MAX ( 'Calendar'[Date] )
RETURN
    CONCATENATEX (
        CALCULATETABLE ( ALL ( 'Calendar'[Date] ), 'Calendar'[Date] >= __date ),
        'Calendar'[Date],
        UNICHAR ( 10 )
    )

 

Then I replace CALCULATETABLE with FILTER, which produces an answer as expected,

 

Correct = 
VAR __date = MAX ( 'Calendar'[Date] )
RETURN
    CONCATENATEX (
        FILTER ( ALL ( 'Calendar'[Date] ), 'Calendar'[Date] >= __date ),
        'Calendar'[Date],
        UNICHAR ( 10 )
    )

 

I understand that in general, context transition occurs while leveraging CALCULATETABLE. Here I didn't manage to figure out which context transit in the calculation. There must be some other reasons resulting in the unexpected answer.🤔

A mockup file is attached for more clarification. Thanks!

 

 


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

1 ACCEPTED SOLUTION
Fowmy
Super User
Super User

@CNENFRNL 

Yes, CALCULATETABLE creates a context transition but FILTER doesn't.  In your case, if you look at the arguments in CALCULATETABLE, after you have applied 'Calendar'[Date] >= __date, you remove filters using ALL ( 'Calendar'[Date] ), that is the reason all dates are in the result. But if you apply VALUES to respect the filters then you can get the correct results with the same formula.

Corrected = 
VAR __date = MAX ( 'Calendar'[Date] )
RETURN
    CONCATENATEX (
        CALCULATETABLE ( VALUES('Calendar'[Date] ), 'Calendar'[Date] > __date ),
        'Calendar'[Date],
        UNICHAR ( 10 )
    )

________________________

If my answer was helpful, please consider Accept it as the solution to help the other members find it

Click on the Thumbs-Up icon if you like this reply 🙂

YouTube  LinkedIn

 

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
Fowmy
Super User
Super User

@CNENFRNL 

Yes, CALCULATETABLE creates a context transition but FILTER doesn't.  In your case, if you look at the arguments in CALCULATETABLE, after you have applied 'Calendar'[Date] >= __date, you remove filters using ALL ( 'Calendar'[Date] ), that is the reason all dates are in the result. But if you apply VALUES to respect the filters then you can get the correct results with the same formula.

Corrected = 
VAR __date = MAX ( 'Calendar'[Date] )
RETURN
    CONCATENATEX (
        CALCULATETABLE ( VALUES('Calendar'[Date] ), 'Calendar'[Date] > __date ),
        'Calendar'[Date],
        UNICHAR ( 10 )
    )

________________________

If my answer was helpful, please consider Accept it as the solution to help the other members find it

Click on the Thumbs-Up icon if you like this reply 🙂

YouTube  LinkedIn

 

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

CNENFRNL
Community Champion
Community Champion

Thank you very much, @Fowmy for such a detaled explanation!


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors