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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
kbandito
Frequent Visitor

DAX to count based on another column

Hi, I am looking for a DAX to count the number of brands available in BBB when I selected AAA.

I need a DAX because i need to build charts that can breakdown the count by category.

 

Table 1: Location

Main locationWithin 3km
AAABBB
AAABBB
BBBCCC

 

Table 2: POI

LocationPOICategory
BBBLVLuxury
BBBGAPFashion
BBBKidsKids
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @kbandito ,

 

You can try to create a measure and put it into a card. When you select AAA, the card returns the number of brands 3 km away from you.

Count =
CALCULATE (
    COUNTROWS ( 'POI' ),
    FILTER (
        'POI',
        [Location]
            = CALCULATE (
                MAX ( 'Location'[Within 3km] ),
                FILTER (
                    'Location',
                    [Main location] = SELECTEDVALUE ( Location[Main location] )
                )
            )
    )
)

1.png

 

You can check more details from here.

 

 

Best Regards,

Stephen Tao

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

Hi @kbandito ,

 

You can try to create a measure and put it into a card. When you select AAA, the card returns the number of brands 3 km away from you.

Count =
CALCULATE (
    COUNTROWS ( 'POI' ),
    FILTER (
        'POI',
        [Location]
            = CALCULATE (
                MAX ( 'Location'[Within 3km] ),
                FILTER (
                    'Location',
                    [Main location] = SELECTEDVALUE ( Location[Main location] )
                )
            )
    )
)

1.png

 

You can check more details from here.

 

 

Best Regards,

Stephen Tao

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Greg_Deckler
Super User
Super User

@kbandito - Maybe:

Measure =
  VAR __Search = MAX(Location[Within 3km])
RETURN
  COUNTROWS(FILTER('POI',[Location]=__Search))

Or

Measure =
  VAR __Search = MAX(Location[Within 3km])
RETURN
  COUNTROWS(DISTINCT(SELECTCOLUMNS(FILTER('POI',[Location]=__Search),"brands",[Category])))

 

Otherwise, please provide additional details.



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!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Hi, the first measures kinda works, but i think the MAX function limits it to show only 1 location.

For example, AAA will have 5 locations in the Within 3km list. Now the measure is only showing the POI count for just 1 location, i will need it to show POI count for all 5 locations when AAA is selected.

amitchandak
Super User
Super User

@kbandito , what is the expected output

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.