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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
RL1
Frequent Visitor

Count values associated with one category but not another

Appologies if this is a simple one, but I'm fairly new to PowerBI and haven't ben able to find an answer using search.

 

Basically I have a table similar to the following:

 

category     value

A                   X

A                   Y

A                   Z

B                   W

B                   X

C                   V

C                  W

 

 

and I want create charts showing counts of the values of A and C that are not associated with B.

i.e. in the above example I want to find Y and Z so get a count of 2 for A and to just count V when looking at C.

 

Thanks

 

4 REPLIES 4
v-yulgu-msft
Microsoft Employee
Microsoft Employee

Hi @RL1,

 

Does below output meet your requirement?

6.PNG

 

If yes, please refer to below steps.

 

Create two calculated tables.

Table For B = CALCULATETABLE('Count Values','Count Values'[Category]="B")

Table For A&C = CALCULATETABLE('Count Values', 'Count Values'[Category]<>"B")

In 'Table For A&C', add a calculated column using LookUpValue function.

Col1 =
IF (
    ISBLANK (
        LOOKUPVALUE (
            'Table For B'[Value],
            'Table For B'[Value], 'Table For A&C'[Value]
        )
    ),
    1,
    BLANK ()
)

Create a measure to show the count of the values of A and C that are not associated with B.

Count for A&C =
CALCULATE (
    COUNT ( 'Table For A&C'[Col1] ),
    ALLEXCEPT ( 'Table For A&C', 'Table For A&C'[Category] )
)

Best regards,
Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Dog
Responsive Resident
Responsive Resident

Hi @RL1

 

you probably just want to create a measure that performs the count of hte category column 

 

CountOfCategories :=
COUNT ( TableName[Category] )

 

Then create another Measure to filter on the Y and Z 

 

CountOfYZ :=
CALCULATE ( [CountOfCategories], [Value] = "Y" || [Value] = "Z" )

 

when you add the category and CountOfYZ to a chart each count should calculate for you. 

 

Hopefully that's what you are after. 

RL1
Frequent Visitor

Thanks,

 

In reality I have thousands of different values so wouldn't want to specify all of them, is it simple to switch this around to specify the category to exclude matching values for rather than the values themselves?

Dog
Responsive Resident
Responsive Resident

is this any help? replace tablename with your tablename, 

 

CategoryNotInB :=
CALCULATE (
[CountOfCategories],
FILTER (
TableName,
NOT (
CONTAINS (
FILTER ( TableName, TableName[category] = "B" ),
TableName[Value], TableName[Value]))))

 

 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.