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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
bk-ikram
Frequent Visitor

DistinctCount , ignoring one filter

Hi, 
Say I am working on the datamodel found in this report :
https://tinyurl.com/2upv9t53

I want to create a similar table to this, where distinct count of customerIds are displayed for all rows (in this case it would be  the number of customerIds in the category group, and ignore all filters on the customers table. So the expected outcome would be something like this:

bkikram_3-1714842023929.png

 

 

I have tried the formula in the screenshot below, but it seems to give me a cartesian product of some sort.

 

bkikram_2-1714841742824.png

 

 

Here is the Customer table showing its mapping with the customergroup table:

bkikram_1-1714841599274.png

 

1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

@bk-ikram Try the following. PBIX attached below signature.

 

Measure = 
    VAR __Group = MAX( 'Customer'[CategoryGroup] )
    VAR __Sales = SUM( 'Sales'[Sales] )
    VAR __CountCustomers = 
        COUNTROWS( 
            DISTINCT(
                SELECTCOLUMNS(
                    FILTER( 
                        ALLSELECTED('Customer'),
                        [CategoryGroup] = __Group
                    ),
                    "__Customer", [Customer Name]
                )
            )
        )
    VAR __Result = IF( __Sales = BLANK(), BLANK(), __CountCustomers )
RETURN
    __Result

 

 


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

2 REPLIES 2
Greg_Deckler
Super User
Super User

@bk-ikram Try the following. PBIX attached below signature.

 

Measure = 
    VAR __Group = MAX( 'Customer'[CategoryGroup] )
    VAR __Sales = SUM( 'Sales'[Sales] )
    VAR __CountCustomers = 
        COUNTROWS( 
            DISTINCT(
                SELECTCOLUMNS(
                    FILTER( 
                        ALLSELECTED('Customer'),
                        [CategoryGroup] = __Group
                    ),
                    "__Customer", [Customer Name]
                )
            )
        )
    VAR __Result = IF( __Sales = BLANK(), BLANK(), __CountCustomers )
RETURN
    __Result

 

 


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Thank you Greg, this solution seems to do the trick. I just thought that there could be a more "straight-forward " solution. I would appreciate it if you could briefly explain why the formula I tried would not work.

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.