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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Anonymous
Not applicable

SUM excluding IDs from Other column in the same table

Hi all,

 

Maybe this is super simple but I just can't figure it out. I have a slicer with multi selection available, when a single Country is selected it should SUM everything in Values just normal but when more than one country is selected I want to aggregate only if the country id doesn't exist in another column call ReferenceCountryID. Keep in mind that my slicer is using column CountryName and not CountryID.

Here is a summary of data and expected results to make it easy to understand:

jmoraga_0-1622478069695.png

 

I tried with ALLEXCEPT, VALUES, etc and nothing.

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Anonymous ,

 

Please check the attachment.

 

1.Create a seperate countryname table.

Screenshot 2021-06-02 162835.png

 

2.Create two measures.

flag = 
VAR _allID =
    SUMMARIZE (
        FILTER (
            ALL ( 'Table' ),
            'Table'[CountryName] IN ALLSELECTED ( 'Table 2'[CountryName] )
        ),
        'Table'[CountryID]
    )
VAR _flag =
    IF (
        MAX ( 'Table'[ReferenceCountryID] )
            IN _allID
                && MAX ( 'Table'[CountryName] ) IN ALLSELECTED ( 'Table 2'[CountryName] ),
        SUM ( 'Table'[Values] )
    )
RETURN
    _flag
Output = 
VAR _countSele =
    COUNTX (
        FILTER ( 'Table', 'Table'[CountryName] IN ALLSELECTED ( 'Table'[CountryName] ) ),
        [CountryName]
    )
VAR _sum =
    CALCULATE (
        SUM ( 'Table'[Values] ),
        FILTER (
            'Table',
            'Table'[CountryName] IN ALLSELECTED ( 'Table 2'[CountryName] )
        )
    )
RETURN
    IF ( _countSele = 1, _sum, _sum - SUMX ( 'Table', [flag] ) )

Screenshot 2021-06-02 163014.png

 

 

 

Best Regards,

Stephen Tao

 

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

2 REPLIES 2
Anonymous
Not applicable

This is really cool, thank you for investing time into my question. Much appriciate it.

 

I found another solution that also works in case anybody has a similar issue:

=VAR CountryList = SUMMARIZE(ALLSELECTED(Facts),Facts[CountryId])
VAR Result = CALCULATE (
SUM([Values])
,FILTER(Facts, NOT(Facts[ReferenceCountryID] IN CountryList ))
)

RETURN
IF(Result = 0, BLANK(),Result)

Anonymous
Not applicable

Hi @Anonymous ,

 

Please check the attachment.

 

1.Create a seperate countryname table.

Screenshot 2021-06-02 162835.png

 

2.Create two measures.

flag = 
VAR _allID =
    SUMMARIZE (
        FILTER (
            ALL ( 'Table' ),
            'Table'[CountryName] IN ALLSELECTED ( 'Table 2'[CountryName] )
        ),
        'Table'[CountryID]
    )
VAR _flag =
    IF (
        MAX ( 'Table'[ReferenceCountryID] )
            IN _allID
                && MAX ( 'Table'[CountryName] ) IN ALLSELECTED ( 'Table 2'[CountryName] ),
        SUM ( 'Table'[Values] )
    )
RETURN
    _flag
Output = 
VAR _countSele =
    COUNTX (
        FILTER ( 'Table', 'Table'[CountryName] IN ALLSELECTED ( 'Table'[CountryName] ) ),
        [CountryName]
    )
VAR _sum =
    CALCULATE (
        SUM ( 'Table'[Values] ),
        FILTER (
            'Table',
            'Table'[CountryName] IN ALLSELECTED ( 'Table 2'[CountryName] )
        )
    )
RETURN
    IF ( _countSele = 1, _sum, _sum - SUMX ( 'Table', [flag] ) )

Screenshot 2021-06-02 163014.png

 

 

 

Best Regards,

Stephen Tao

 

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

 

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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