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
Anonymous
Not applicable

Filtering Top 3 Cities & top 3 sales managers within the cities

I'm trying to create a matrix with the top 3 cities & top 3 sales managers within the cities. So far i managed the ranking till the cities. Request help to include the ranking of the sales managers too.

 

The below dax currently ranks all zones and the top 3 cities within each zone.

 

DAX so far-

Rank_Zone_City = IF (
ISINSCOPE( 'Location'[City] ),
RANKX (
CALCULATETABLE (
VALUES ( 'Location'[City] ),
ALLSELECTED ( 'Location'[City] )
),
[Sales Last Month]
),
IF (
ISINSCOPE( 'Location'[Zone] ),
RANKX (
ALLSELECTED ( 'Location'[Zone] ),
[Sales Last Month]
)
)
)

 

Appreciate the help!

 

4 REPLIES 4
v-alq-msft
Community Support
Community Support

Hi, @Anonymous 

 

Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.

Table:

b1.png

 

You may create a measure as below.

Visual Control = 
var tab = 
CALCULATETABLE(
    DISTINCT('Table'[City]),
    TOPN(
        3,
        SUMMARIZE(
             ALL('Table'),
             'Table'[City],
             "Sum",
             SUM('Table'[Sales])
        ),
        [Sum]
    )
)
var newtab = 
CALCULATETABLE(
    DISTINCT('Table'[Zone]),
    TOPN(
        3,
        SUMMARIZE(
            FILTER(
                ALL('Table'),
                'Table'[City]=SELECTEDVALUE('Table'[City])
            ), 
            [Zone],
            "Sum",
            SUM('Table'[Sales])
        ),
        [Sum]
    )
)
return
    IF(
        ISINSCOPE('Table'[Zone])&&SELECTEDVALUE('Table'[City]) in tab,
        IF(
            SELECTEDVALUE('Table'[Zone]) in newtab,
            1,0
        ),
        IF(
            ISINSCOPE('Table'[City]),
            IF(
                SELECTEDVALUE('Table'[City]) in tab,
                1,0
            )
        )
    )

 

Finally you need to put the measure in the visual level filter to filter the result.

Without filter:

b2.png

 

Filtered result:

b3.png

 

Best Regards

Allan

 

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

Anonymous
Not applicable

@v-alq-msft i'm trying to implement the below logic -
Zones - North, South, etc --> should show up total sales for the zone (not just top 3 city total)
Cities - Delhi, Punjab, Haryana…etc --> should show up total sales for the city (not just top 3 sales manager sales total)
Sales Managers - A,B, C, D,…. T --> should show up total sales for the indivudal sales managers within that city & zone

 

And my matrix should look like - 

 

 RankUnfiltered sales
North1100
Delhi130
A15
B23
C32
Punjab210
D14
E22
F31
Haryana39
G13
H22
I31
South290
Kerela130
L110
M26
N34
Tamil Nadu220
0110
P23
Q32
Pondicherry315
R17
S22
T31
Anonymous
Not applicable

@amitchandak  https://www.sqlbi.com/articles/filtering-the-top-3-products-for-each-category-in-power-bi/ is limited to only 2 hierarchies, all the other rank articles shared either creates different rank columns for the sub category and category ( i need it on the same column) or shows for only two hierarchies 

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.