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

Exclude whole group if value is found

I am trying to calculate in Power BI values (Sum) for the Items that have only user specified value in column Code. In my case the the whole row should be excluded if the value is other than "X". For example Item AA should be excluded because it has also value "Z".

 

Item	Code	Amount
AA	X	1
AA	X	2
AA	Z	3
BB	X	4
BB	Y	5
BB	Z	6
BB	X	7
CC	X	8
CC	X	9

Table1

 Any ideas how to do this? The end result should be like this:

 

Item	Code	Sum
CC	X	17

This is as far I have gotten:

SumByItem = CALCULATE(SUM(Table1[Amount]),ALLEXCEPT(Table1,Table1[Item]))

 

 

The rows are summed by Item but I am strugling with the exclusion part. Appreciate any help! Thanks

1 ACCEPTED SOLUTION
v-yuta-msft
Community Support
Community Support

Hi Ildoin,

 

To achieve your requirement, you can create a calculate column like below:

IsValid Column = 
IF (
    CALCULATE (
        COUNTROWS(Table1),
        ALLEXCEPT ( Table1, Table1[Item] )
    )
        <> CALCULATE(COUNTROWS(Table1), ALLEXCEPT(Table1, Table1[Item], Table1[Code])),
    FALSE(),
    IF (
        CALCULATE (
            VALUES ( Table1[Code] ),
            ALLEXCEPT ( Table1, Table1[Item], Table1[Code] )
        )
            <> "X",
        FALSE(),
        TRUE ()
    )
)

1.PNG 

Then create a slicer based on IsValid Column, select True, you will achieve what you want.

2.PNG 

 

Hope it's helpful to you.

 

Jimmy Tao

View solution in original post

3 REPLIES 3
itsme-stephanie
Frequent Visitor

I'm facing almost the same problem, except that I want to exclude the whole group if the value X is found.

So if we would extend the intital example:

Item	Code	Amount
AA	X	1
AA	X	2
AA	Z	3
BB	X	4
BB	Y	5
BB	Z	6
BB	X	7
CC	X	8
CC	X	9
DD Y 1
DD Z 2
EE Y 3
EE Z 4
EE Z 5

Table1

 

My ask would be how to get only a "true" for DD & EE:

 

Item	IsValidColumn	
AA      False
BB False
CC False
DD True
EE True

 

I've tried to adapt the calculated column example, but it didn't worked out.

Any hint appriciated.

 

v-yuta-msft
Community Support
Community Support

Hi Ildoin,

 

To achieve your requirement, you can create a calculate column like below:

IsValid Column = 
IF (
    CALCULATE (
        COUNTROWS(Table1),
        ALLEXCEPT ( Table1, Table1[Item] )
    )
        <> CALCULATE(COUNTROWS(Table1), ALLEXCEPT(Table1, Table1[Item], Table1[Code])),
    FALSE(),
    IF (
        CALCULATE (
            VALUES ( Table1[Code] ),
            ALLEXCEPT ( Table1, Table1[Item], Table1[Code] )
        )
            <> "X",
        FALSE(),
        TRUE ()
    )
)

1.PNG 

Then create a slicer based on IsValid Column, select True, you will achieve what you want.

2.PNG 

 

Hope it's helpful to you.

 

Jimmy Tao

Gazzer
Resolver II
Resolver II

I don't know how to write the DAX for this (someone cleverer will come along soon, I'm sure) but I did this using built-in Power BI functions.

 

I duplicated your table and then filtered it to KEEP rows where the Code - 'Z'

Then I merged the first table with the new, filtered duplicate, using an 'anti' join type.

 

image.png

 

Lastly, I used Group By on the Item column and aggregated the Amount to get the desired outcome.

 

 

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.