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

Return Rank Value and Show as Label On Map

Hi,

 

I have a question now. I have a table with columns including city, longtitude, latitude, product. I want to do a map visual -- Best product by city. The lable on the map will be "city name - its best product name".  Below is the data sample:

 

My question is how to add a new column to return produt who has the max count for different cities?  Then I can put the column as the location in the map and lable can show the product name in each city.

 

CITYLONGTITUDELATITUDEProduct
LOS ANGELES-118.29866233.786594BM
LYNWOOD-118.20295433.924538BM
LOS ANGELES-118.24495533.921065MBZ
ENCINO-118.29866233.786594BM
SANTA MONICA-115.56748334.202339BM
SAN BERNARDINO-116.22839334.134794LEX
LONG BEACH-118.18110233.831466CHE
LOS ANGELES-118.28570633.938108FOR
CARSON-118.26115433.813317BM
COMPTON-118.2168133.879565CHE
SANTA MONICA-115.56748334.202339LINC
SANTA MONICA-115.56748334.202339BM
SAN BERNARDINO-116.22839334.134794HON
CORONA-116.05561733.752886INF
LOS ANGELES-118.29866233.786594MBZ
LYNWOOD-118.20295433.924538GMC
SAN BERNARDINO-116.22839334.134794HON
COMPTON-118.24020833.874815LEX
COMPTON-118.24020833.874815CHE
SANTA MONICA-115.56748334.202339BM

 

Thanks!

1 ACCEPTED SOLUTION
Phil_Seamark
Employee
Employee

Hi @Gracie

 

You could try adding these three calculated columns to your table.

 

Count of Products Per City = 
var CityColumn = 'Table1'[CITY]
var ProductColumn = 'Table1'[Product]
var ProductCount = 
    CALCULATE(
        COUNTROWS('Table1'),
        FILTER('Table1',
            'Table1'[CITY] = CityColumn
            && 'Table1'[Product] =ProductColumn
            )
        )
    
return ProductCount       
Top Products = 
var CountColumn = 'Table1'[Count of Products Per City]
var CityColumn = 'Table1'[CITY]
var TopProducts = 
    IF(
    CALCULATE(
        COUNTROWS('Table1'),
        FILTER('Table1',
            'Table1'[CITY]=CityColumn
            && Table1[Count of Products Per City] > CountColumn
            )
            )+0 =0,
            1,
            0)
return TopProducts        


Best Product = 
var CityColumn = ('Table1'[CITY])
var BestProduct = CONCATENATEX(
    FILTER(
            SUMMARIZE(
                FILTER('Table1','Table1'[Top Products]=1),
                'Table1'[CITY],
                Table1[Product]
                ),'Table1'[CITY]=CityColumn)
                ,'Table1'[Product] & " ")
return BestProduct

and then drag the last column to your tooltip.

 

 

 


To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

View solution in original post

2 REPLIES 2
Phil_Seamark
Employee
Employee

Hi @Gracie

 

You could try adding these three calculated columns to your table.

 

Count of Products Per City = 
var CityColumn = 'Table1'[CITY]
var ProductColumn = 'Table1'[Product]
var ProductCount = 
    CALCULATE(
        COUNTROWS('Table1'),
        FILTER('Table1',
            'Table1'[CITY] = CityColumn
            && 'Table1'[Product] =ProductColumn
            )
        )
    
return ProductCount       
Top Products = 
var CountColumn = 'Table1'[Count of Products Per City]
var CityColumn = 'Table1'[CITY]
var TopProducts = 
    IF(
    CALCULATE(
        COUNTROWS('Table1'),
        FILTER('Table1',
            'Table1'[CITY]=CityColumn
            && Table1[Count of Products Per City] > CountColumn
            )
            )+0 =0,
            1,
            0)
return TopProducts        


Best Product = 
var CityColumn = ('Table1'[CITY])
var BestProduct = CONCATENATEX(
    FILTER(
            SUMMARIZE(
                FILTER('Table1','Table1'[Top Products]=1),
                'Table1'[CITY],
                Table1[Product]
                ),'Table1'[CITY]=CityColumn)
                ,'Table1'[Product] & " ")
return BestProduct

and then drag the last column to your tooltip.

 

 

 


To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

Hi @Phil_Seamark

 

Thanks for your solutions. I tried and it worked mostly. However, there still has some rows that didn't calculate correctly. I don't if it's the problem of formulas or the fields format.

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.