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
echow
Helper II
Helper II

How to write Filter and AllExcept if I have a couple of parameters to filter?

HI,

 

I need help on creating a DAX for filtering the following result in column E to H.

Basically, I need to create a 'Filter All' by Age and the year. And for the Age I would like it to ignore the calculation for the band Age_99 and be able to differentiate between two company type (A & B)

 

For Column F(Filter All), I believe the DAX language is something like this

Filter All= CALCULATE([Total Count],

FILTER(ALLEXCEPT(Table1,Table1[Company Type]),
Table1[AGE_ID] <> "AG_99"))
 
But how do I go about writing the filter  for column H to K if I would like to have the result filter by year.
 
PowerBI Help.png
 
 

Appreciate if someone can help on this.

 

1 ACCEPTED SOLUTION

Thanks @v-joesh-msft I think I have it figured out, that is to include the year parameter in the filter allexecept.

Total Age Count =
CALCULATE (
    [Total Count],
    FILTER ( ALLEXCEPT ( Table1, Table1[Year], Table1[CompanyType]),
    Table1[AGE_ID] <> "AG_99" ))

 

View solution in original post

6 REPLIES 6
tex628
Community Champion
Community Champion

I think something like this should work:

Filter 2017 =
IF( SELECTEDVALUE(Calendar[Year]) = 2017 ,
CALCULATE([Total Count],
FILTER(ALLEXCEPT(Table1,Table1[Company Type]),
Table1[AGE_ID] <> "AG_99"),
Calendar[Year] = 2017
),
BLANK()
)

 

Filter 2017/2018 =
IF( SELECTEDVALUE(Calendar[Year]) = 2017 || SELECTEDVALUE(Calendar[Year]) = 2018 ,
CALCULATE([Total Count],
FILTER(ALLEXCEPT(Table1,Table1[Company Type]),
Table1[AGE_ID] <> "AG_99"),
Calendar[Year] = 2017 || Calendar[Year] = 2018
),
BLANK()
)

Connect on LinkedIn

Let's just say I do not want to explicitly call out the year, but it is a year filter that will aggregate these numbers accordingly.

tex628
Community Champion
Community Champion

Alright. In that case i will need to know how the selection logic is supposed to work. Could you give some examples of displayed columns with different selections on year? 


Connect on LinkedIn

Basically, rather than me specifying the year, I will allow the user to choose the year. 

 

I wrote something based on what you have but I got the most outer left table output.

What I would want is the most outer right table output

 

Total Age Count =
VAR CurrentYear = SELECTEDVALUE(Table1[YEAR])
RETURN

CALCULATE([Total Count],
FILTER(ALLEXCEPT(Table1,Table1[CompanyType]),
Table1[AGE_ID] <> "AG_99"),
Table1[YEAR] = CurrentYear)
 
PowerBI Help1.png

Hi @echow ,

I think what you need is the following measure:

Total Age Count =
CALCULATE (
    [Total Count],
    FILTER ( ALLEXCEPT ( Table1, Table1[CompanyType] ), Table1[AGE_ID] <> "AG_99" )
)

Best Regards,
Community Support Team _ Joey
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Thanks @v-joesh-msft I think I have it figured out, that is to include the year parameter in the filter allexecept.

Total Age Count =
CALCULATE (
    [Total Count],
    FILTER ( ALLEXCEPT ( Table1, Table1[Year], Table1[CompanyType]),
    Table1[AGE_ID] <> "AG_99" ))

 

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.