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
adityo
Frequent Visitor

ignore filters when sum amount based on Max Year

Hi All,

I want to make calculations Current year*,that ignore my filter selections

*Current Year calculation is sum of amount of Max of Current year in AP_Database table 

 

here are my scheme :

Date.Clearing one to many AP_Database.Clearing

adityo_0-1629166828398.png

 
here are my measures
Current Year New =
var MaxYear = CALCULATE(MAX('Date'[Year Outgoing]), ALL('Date'[Year Outgoing]))
RETURN
CALCULATE(SUM(AP_Database[Amount in local cur.]),FILTER(ALL('Date'[Year Outgoing]), 'Date'[Year Outgoing]=MaxYear))

 

but it seems doesn't work.

When i filtered table Date, it also filtered the Current Year New

1 ACCEPTED SOLUTION

Hi @adityo ,

 

It is because you are using ALL() function in the formula. Try using ALLEXCEPT() function instead.

measure 1 = CALCULATE(SUM(AP_Database[Amount in local cur.]),FILTER(ALLEXCEPT(AP_Database,AP_Database[category]), YEAR(AP_Database[Clearing])=MaxYear))

measure 2 = CALCULATE(SUM(AP_Database[Amount in local cur.]),FILTER(ALL(AP_Database), YEAR(AP_Database[Clearing])=MaxYear&&AP_Database[category]=SELECTEDVALUE(AP_Database[category])))

 If both the above measures don't work, please show some sample data and expected result to us.

 

Best Regards,

Jay

Community Support Team _ Jay
If this post helps, then please consider Accept it as the solution
to help the other members find it.

View solution in original post

7 REPLIES 7
v-jayw-msft
Community Support
Community Support

Hi @adityo 

 

Current Year New =
var MaxYear = CALCULATE(MAX('Date'[Year Outgoing]), ALL('Date'[Year Outgoing]))
RETURN
CALCULATE(SUM(AP_Database[Amount in local cur.]),FILTER(ALL(AP_Database), YEAR(AP_Database[Clearing])=MaxYear))
 
You need to use the date in AP_Database to match the date in Date table.
 
Best Regards,
Jay
Community Support Team _ Jay
If this post helps, then please consider Accept it as the solution
to help the other members find it.

Im aorey but this is one of the worst advice I saw on this forum.

 

For god sake, dont use filter( All(Ap_database)). What if this table has million rows, you will end up iterating on all the rows.

 

  • Always filter colums in the dimensions and use the relationship.

The approach from @amitchandak is really better in this case.

@v-jayw-msft it seems work.... it calculates the current year. but i think it will mislead the context. while im using matrix for the visualization, all the number are same for all category....

Hi @adityo ,

 

It is because you are using ALL() function in the formula. Try using ALLEXCEPT() function instead.

measure 1 = CALCULATE(SUM(AP_Database[Amount in local cur.]),FILTER(ALLEXCEPT(AP_Database,AP_Database[category]), YEAR(AP_Database[Clearing])=MaxYear))

measure 2 = CALCULATE(SUM(AP_Database[Amount in local cur.]),FILTER(ALL(AP_Database), YEAR(AP_Database[Clearing])=MaxYear&&AP_Database[category]=SELECTEDVALUE(AP_Database[category])))

 If both the above measures don't work, please show some sample data and expected result to us.

 

Best Regards,

Jay

Community Support Team _ Jay
If this post helps, then please consider Accept it as the solution
to help the other members find it.

Thx @v-jayw-msft it works perfect!

amitchandak
Super User
Super User

@adityo , Try one of the two

 

Current Year New =
var MaxYear = year(today())
RETURN
CALCULATE(SUM(AP_Database[Amount in local cur.]),FILTER(ALL('Date'[Year Outgoing]), 'Date'[Year Outgoing]=MaxYear))


Current Year New =
var MaxYear = maxx(all('Date'), 'Date'[Year Outgoing])
RETURN
CALCULATE(SUM(AP_Database[Amount in local cur.]),FILTER(ALL('Date'[Year Outgoing]), 'Date'[Year Outgoing]=MaxYear))

@amitchandak thank you for your response, unfortunately both of them doesn't works. the DAX script doesn't return error. but it keep filtered.

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.