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
Anonymous
Not applicable

SUM with ALL, CONTAINS and Filter

I am trying to write a dax formula in Tabular model to calculate the SUM of CarParc colum.  To calculate the SUM I want to reatain the Filter added with Contains but ignore all other filters. Please help to know ho to achieve. Below formula  with ALL gives some different result whihc is not expected.

 

SUMX(
FILTER( ADDCOLUMNS(
SUMMARIZE(Fact_Planned_CarParc; Fact_Planned_CarParc[Year]; Fact_Planned_CarParc[FactoryCode]);
"Age"; selectedyear - Fact_Planned_CarParc[Year]
;"totalcount"; CALCULATE(SUM(Fact_Planned_CarParc[CarParc]); ALL(Fact_Planned_CarParc[Year])));
CONTAINS(Dim_AgeInterval;Dim_AgeInterval[AgeId];[Age]))
; [totalcount])

 

1 ACCEPTED SOLUTION

Hi @Anonymous ,

 

Try to modify as below:

SUMMARIZE(ALL(Fact_Planned_CarParc); Fact_Planned_CarParc[Year]; Fact_Planned_CarParc[FactoryCode]; "Age"; selectedyear - Fact_Planned_CarParc[Year]
;"totalcount"; CALCULATE(SUM(Fact_Planned_CarParc[CarParc])));
CONTAINS(Dim_AgeInterval;Dim_AgeInterval[AgeId];[Age])

 

Best Regards,
Kelly
Did I answer your question? Mark my post as a solution!

View solution in original post

3 REPLIES 3
amitchandak
Super User
Super User

@Anonymous ,

what you want to filter is not clear

SUMX(
FILTER( ADDCOLUMNS(
SUMMARIZE(Fact_Planned_CarParc; Fact_Planned_CarParc[Year]; Fact_Planned_CarParc[FactoryCode]);
"Age"; selectedyear - Fact_Planned_CarParc[Year]
;"totalcount"; CALCULATE(SUM(Fact_Planned_CarParc[CarParc]); ALL(Fact_Planned_CarParc[Year])));
filter(Dim_AgeInterval, CONTAINS(Dim_AgeInterval;Dim_AgeInterval[AgeId];[Age])))
; [totalcount])

 

You can add filter clause like Fact_Planned_CarParc[Year] in allselected(Fact_Planned_CarParc[Year])

Fact_Planned_CarParc[Year] in values(Fact_Planned_CarParc[Year])

Anonymous
Not applicable

@amitchandak 

 

I am working on the older version of SSAS. It does not support IN.

I want to calculate below and ignore any other filter applied on Fact_Planned_Carparc table

 

SUMMARIZE(Fact_Planned_CarParc; Fact_Planned_CarParc[Year]; Fact_Planned_CarParc[FactoryCode]; "Age"; selectedyear - Fact_Planned_CarParc[Year]
;"totalcount"; CALCULATE(SUM(Fact_Planned_CarParc[CarParc])));
CONTAINS(Dim_AgeInterval;Dim_AgeInterval[AgeId];[Age])

Hi @Anonymous ,

 

Try to modify as below:

SUMMARIZE(ALL(Fact_Planned_CarParc); Fact_Planned_CarParc[Year]; Fact_Planned_CarParc[FactoryCode]; "Age"; selectedyear - Fact_Planned_CarParc[Year]
;"totalcount"; CALCULATE(SUM(Fact_Planned_CarParc[CarParc])));
CONTAINS(Dim_AgeInterval;Dim_AgeInterval[AgeId];[Age])

 

Best Regards,
Kelly
Did I answer your question? Mark my post as a solution!

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.