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
QuantamPulse
New Member

Question about displaying previous year data over current year data

I have an issue displaying previous year data over current year data for a date range selected in a slicer. 

 

I use the following to set up the measures and have them set to display on a line graph. 

 

Sakes Data Count Current Year = COUNTROWS(requestTable)
Sales Data Count Previous Year = CALCULATE(
    COUNTROWS(requestTable),
    FILTER(
        ALL(requestTable),
        YEAR(requestTable[Date]) = YEAR(MAX(requestTable[Date])) - 1
        && FORMAT(requestTable[Date], "MMM") = FORMAT(MAX(requestTable[Date]), "MMM")
    )
)

 

 

And this works fine until another filter is applied, for example, a Needs slicer. The current year data adjusts, but the previous year data does not. I have tried chaning ALL to ALLSELECTED instead, but them the entire line on the chart for the previous year disappears. 

 

Not sure what I am doing wrong here but any help would be appriciated. 

 

2 ACCEPTED SOLUTIONS
Greg_Deckler
Super User
Super User

@QuantamPulse Maybe try ALLEXCEPT


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

Hi @QuantamPulse 

Certainly, you can understand it as:

vzhengdxumsft_0-1708661764429.png

The columns from the specified table for which you want to keep filters. Filters on all other columns will be removed.

The primary use case of ALLEXCEPT is to create calculations within a particular context while disregarding filters applied to other columns. This is especially handy in scenarios where you need to perform calculations within a specific dimension or attribute of your data, ignoring filters on other dimensions.

Here is a blog about the understanding of context:

Understand the Filter Context and How to Control i... - Microsoft Fabric Community

Links of ALLEXCEPT():

Demystifying the ALLEXCEPT Function in DAX | by Andrew Hubbard | Microsoft Power BI | Medium

The Power BI ALLEXCEPT function (datascientest.com)

 

Best Regards

Zhengdong Xu
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

4 REPLIES 4
Greg_Deckler
Super User
Super User

@QuantamPulse Maybe try ALLEXCEPT


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Do you happen to know if you can specify multiple columns in the ALLEXCEPT function? The documentation on it is a little unclear. 

 

The documentation shows the following context but I'm not sure why there would be a comma inside of a bracket?

ALLEXCEPT(Table, Column1 [,Column2]...)

Hi @QuantamPulse 

Certainly, you can understand it as:

vzhengdxumsft_0-1708661764429.png

The columns from the specified table for which you want to keep filters. Filters on all other columns will be removed.

The primary use case of ALLEXCEPT is to create calculations within a particular context while disregarding filters applied to other columns. This is especially handy in scenarios where you need to perform calculations within a specific dimension or attribute of your data, ignoring filters on other dimensions.

Here is a blog about the understanding of context:

Understand the Filter Context and How to Control i... - Microsoft Fabric Community

Links of ALLEXCEPT():

Demystifying the ALLEXCEPT Function in DAX | by Andrew Hubbard | Microsoft Power BI | Medium

The Power BI ALLEXCEPT function (datascientest.com)

 

Best Regards

Zhengdong Xu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Never used ALLEXCEPT before. Worked perfectly. Set the column in the parameters to the column that I needed filtering by and it worked like a charm. 


Thanks!

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.