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

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.

Reply
Anonymous
Not applicable

Filterall calulation does not work in variables

Good sunday everyone

 

Does anyone know why when I use  filter(all()) calculations, if it is in a variable measure it does not work but as a separate measure it will work. 

 

For e.g., 

VAR totalsalesofshoes = calculate(sum(totalsales), type = shoes 

return calculate(totalsalesofshoes,(filter(all(calendar),index>

= max(dim_Calendar[Index])-5 && dim_Calendar[Index]<= MAX(dim_Calendar[Index]))))
 
but if split the return portion into a separate measure, it calculates correctly. If I don't split it the max index portion does not get calculated at all. 

 

1 ACCEPTED SOLUTION
jdbuchanan71
Super User
Super User

@Anonymous Take a look at this article discussing the topic.
https://radacad.com/caution-when-using-variables-in-dax-and-power-bi

Basically, the CALCULATE will not do anything to the VAR totalsalesofshoes the way your measure is written.

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

Ohh thanks for the article. Then what do u suggest I do? Create a separate measure or is there another solution?

Yes, make it into two measures.

totalsalesofshoes =
    CALCULATE ( SUM ( totalsales[Sales] ), type = shoes )
Final Measure =
CALCULATE (
    [totalsalesofshoes],
    FILTER (
        ALL ( calendar ),
        index
            >= MAX ( dim_Calendar[Index] ) - 5
            && dim_Calendar[Index] <= MAX ( dim_Calendar[Index] )
    )
)

 

Fowmy
Super User
Super User

@Anonymous 

You cannot use a variable like "totalsalesofshoes" as n expression inside CALCULATE. The variable will not be affected by filters therein.


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

jdbuchanan71
Super User
Super User

@Anonymous Take a look at this article discussing the topic.
https://radacad.com/caution-when-using-variables-in-dax-and-power-bi

Basically, the CALCULATE will not do anything to the VAR totalsalesofshoes the way your measure is written.

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Kudoed Authors