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
ajmonster
Helper II
Helper II

DISTINCTCOUNT ignoring filter context

Here's my data model:

Stores 1-* Sales

Each Store is associated with a Market, Zone, and ZIP Code. My goal is to return the associated Store count for each Market, Zone, and ZIP Code for a specific store. So in practice, when a user filters to a specific Store Number, I will be able to return the count of stores in the Market, Zone, and ZIP Code associated with the filtered store. My Zone measure is as follows and works as expected:

Store Count, Zone =
CALCULATE(
    DISTINCTCOUNT('Sales'[Store Number]), 
    ALLEXCEPT( 
        'Store Key', 
        'Store Key'[Zone] 
    ), 
    NOT(ISBLANK('Sales'[$ Sales])) 
)

However, when I use the same measure but replace Zone with Market or Zip Code, the measure does not work as intended and instead returns the full count of all the stores. Also, the Market and Zip Code measures work as intended when there are Market and Zip Code contexts present in the visual; if I bring in the measure to a visual that has the Market/Zip Code dimensions, I get the value I desire.

I'm not sure what's going on at this point and why only the Zone measure works. TIA.

2 REPLIES 2
v-gizhi-msft
Community Support
Community Support

Hi,

 

Please try this(etc. for [Market]):

Store Count, Zone =
CALCULATE (
    DISTINCTCOUNT ( 'Sales'[Store Number] ),
    FILTER (
        ALLSELECTED ( 'Store Key' ),
        'Store Key'[Market] IN FILTERS ( 'Store Key'[Market] )
    ),
    NOT ( ISBLANK ( 'Sales'[$ Sales] ) )
)

Hope this helps.

 

Best Regards,

Giotto

az38
Community Champion
Community Champion

Hi @ajmonster 

at first sight I see a couple of options, depending on your data model and use cases

Store Count, Zone =
CALCULATE(
    DISTINCTCOUNT('Sales'[Store Number]), 
    ALLEXCEPT( 
        'Store Key', 
        'Store Key'[Zone],
        'Store Key'[Market],
        'Store Key'[ZIP Code] 
    ), 
    NOT(ISBLANK('Sales'[$ Sales])) 
)

or

Store Count, Zone =
CALCULATE(
    DISTINCTCOUNT('Sales'[Store Number]), 
    ALLSELECTED( 
        'Store Key' 
     ), 
    NOT(ISBLANK('Sales'[$ Sales])) 
)

do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

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.

Top Solution Authors