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

Summing items from categories that fulfil a criteria

Hi, I would like to compute the total number of units for categories that have more than 2 distinct users, and display the total as a measure using DAX.

First, I have to figure out which categories have more than 2 distinct users.
Then, I would like to sum all the units for these categories.

This "fact_units" table is an example of the input fact table.

Category UserUnits
Cat A10013
Cat A10024
Cat A10031
Cat B10014
Cat B10014
Cat C10032
Cat D10043
Cat D10051
Cat D10066
Cat D10073


As an intermediate step, the table illustrated below removes category B and C because they have 1 distinct user each.

CategoryDistinct usersUnit subtotal
Cat A38
Cat D414


Finally, the measure should return 22.
 
How can I go about doing this? Thanks in advance 🙂

2 ACCEPTED SOLUTIONS
johnt75
Super User
Super User

Try

Units multiple users =
VAR CategoriesAndUsers =
    ADDCOLUMNS (
        VALUES ( 'Fact Units'[Category] ),
        "@num users", CALCULATE ( DISTINCTCOUNT ( 'Fact Units'[User] ) )
    )
VAR FilteredCategories =
    FILTER ( CategoriesAndUsers, [@num users] > 1 )
VAR Result =
    CALCULATE ( SUM ( 'Fact Units'[Units] ), FilteredCategories )
RETURN
    Result

View solution in original post

Ashish_Mathur
Super User
Super User

Hi,

The answer should be 21.

PBI file attached.

Hope this helps.

Ashish_Mathur_0-1732840028621.png

 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

4 REPLIES 4
Bibiano_Geraldo
Community Champion
Community Champion

Hi @yf_f ,

You can achieve your goal by this DAX measure:

Units for Categories with More Than 2 Users = 
SUMX (
    FILTER (
        ALL ('Fact_Units'[Category]), 
        CALCULATE ( DISTINCTCOUNT ('Fact_Units'[User]) ) > 2
    ),
    CALCULATE ( SUM ('Fact_Units'[Units]) )
)

 

it will return 21 as shown bellow:

Bibiano_Geraldo_0-1732876354408.png

 

 

I hope this helps! 
If you found this answer helpful:
✔️ Mark it as the solution to help others find it faster.
 Give it a like to show your appreciation!

Thank you for contributing to our amazing Power BI community! 
Ashish_Mathur
Super User
Super User

Hi,

The answer should be 21.

PBI file attached.

Hope this helps.

Ashish_Mathur_0-1732840028621.png

 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
FreemanZ
Super User
Super User

hi @yf_f ,

 

you may also try like:

measure =

SUMX(

FILTER(

ADDCOLUMNS(

VALUES(fact[Category]),

"UserCount",

CALCULATE(DISTINCTCOUNT(fact[User])),

"UnitsTtl",

CALCULATE(SUM(fact[Units]))

),

[UserCount]>1

),

[UnitsTtl]

)

johnt75
Super User
Super User

Try

Units multiple users =
VAR CategoriesAndUsers =
    ADDCOLUMNS (
        VALUES ( 'Fact Units'[Category] ),
        "@num users", CALCULATE ( DISTINCTCOUNT ( 'Fact Units'[User] ) )
    )
VAR FilteredCategories =
    FILTER ( CategoriesAndUsers, [@num users] > 1 )
VAR Result =
    CALCULATE ( SUM ( 'Fact Units'[Units] ), FilteredCategories )
RETURN
    Result

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!

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.