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

SELECTEDVALUE doesn't work indirectly

Hello,

 

When I use this measure:

Sales Selected Year = CALCULATE(SUM(fSales[Value]), FILTER(ALL(dCalendar), dCalendar[Year] = SELECTEDVALUE(dCalendar[Year]))

 

It brings all sales from 2018 (considering I did the filter for only that year in a slicer visual). However, if I define:

Selected Year = SELECTEDVALUE(dCalendar[Year])

 

and then rewrite the expression as:

Sales Selected Year = CALCULATE(SUM(fSales[Value]), FILTER(ALL(dCalendar), dCalendar[Year] = [Selected Year]))

It brings the sales from all years from the dCalendar table, even tought I filtered just the year of 2018 in the page.

 

How does that happen? Can't I use a value returned in a measure resulted by SELECTEDVALUE function to pass as a filter?

 

*There is a date relationship between fSales and dCalendar.

 

Thanks.

1 ACCEPTED SOLUTION

Accepted Solutions

Re: SELECTEDVALUE doesn't work indirectly

Welcome to the fun world of DAX filter context.  

 

The CALCULATE function is quite magical in the way it can create a new filter context for the expression to work with.

 

If you would like your calculation to work the way you want, please try this.

 

Sales Selected Year = 
VAR x = [Selected Year]
RETURN 
    CALCULATE(
        SUM(fSales[Value]), 
        FILTER(ALL(dCalendar), dCalendar[Year] = x )
        )

To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

View solution in original post

2 REPLIES 2

Re: SELECTEDVALUE doesn't work indirectly

Welcome to the fun world of DAX filter context.  

 

The CALCULATE function is quite magical in the way it can create a new filter context for the expression to work with.

 

If you would like your calculation to work the way you want, please try this.

 

Sales Selected Year = 
VAR x = [Selected Year]
RETURN 
    CALCULATE(
        SUM(fSales[Value]), 
        FILTER(ALL(dCalendar), dCalendar[Year] = x )
        )

To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

View solution in original post

FelipeGualberto Frequent Visitor
Frequent Visitor

Re: SELECTEDVALUE doesn't work indirectly

Thanks, Phil!

 

Strangely enough, the calculation is working now in both methods in another computer.

 

But it is very good to learn this technique, so now I know that sometimes I have to access a measure indirectly using a variable.

 

Have a good day!

Helpful resources

Announcements
New Topics Started Badges Coming

New Topics Started Badges Coming

We're releasing new versions of the badge that everyone's talking about. ;) Check your inbox for notifications.

MBAS 2020

Save the new date (and location)!

Our business applications community is growing—so we needed a different venue, resulting in a new date and location. See you there!

Difinity Conference

Difinity Conference

The largest Power BI, Power Platform, and Data conference in New Zealand

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

Top Solution Authors
Top Kudoed Authors (Last 30 Days)