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
nalanis
Regular Visitor

RankX - Trying to create table that displays dynamic top 10 with an other group

Hello,

 

I am working on a table in Power BI and am trying to display a dynamic top 10 with "Other" based on Current Year Sales (CY Sales). However, I am only able to get the top 10 to display but not the Others. I have scoured the web looking for a solution and came across the following measure: 

 

Top10 = IF(Sales[Rank (Coord_Company)] <= 10, Sales[Sum of CY Sales], IF(HASONEVALUE(Sales[Coord Company]),IF(VALUES(Sales[Coord Company]) = "Others", SUMX( FILTER(ALL(Sales[Coord Company]),Sales[Rank (Coord_Company)] > 10), Sales[Sum of CY Sales]))))

 

However, when I apply the formula it does not provide the "Other" group. What am I missing? Coord Company is a column, Top 10 is a measure, and Rank(Coord_Company) is a measure. 

 

 

 

Capture.PNG

Any feedback is appreciated. Thank you

1 ACCEPTED SOLUTION

Hi @nalanis,

 

You are right. No "Others" exists. That's the cause. 

1. Create a new table for all the Companies.

Companies =
UNION (
    FILTER (
        DISTINCT ( VALUES ( Sales[Coord Company] ) ),
        ISBLANK ( [Coord Company] ) = FALSE ()
    ),
    { "Others" }
)

2. Create a relationship between "Sales" and "Companies".

3. Create a new measure of Ranks.

RankxCompany =
RANKX (
    ALL ( 'Companies'[Coord Company] ),
    CALCULATE ( SUM ( Sales[CY Sales] ) )
)

4. Create a measure "Top10".

Top10 =
VAR ComRank = [RankxCompany]
RETURN
    IF (
        ComRank < 10,
        SUM ( Sales[CY Sales] ),
        IF (
            MIN ( 'Companies'[Coord Company] ) = "Others",
            CALCULATE (
                SUMX (
                    SUMMARIZE (
                        'Companies',
                        Companies[Coord Company],
                        "CQuantity", SUM ( Sales[CY Sales] ),
                        "CRank", RANKX (
                            ALL ( Companies[Coord Company] ),
                            CALCULATE ( SUM ( Sales[CY Sales] ) )
                        )
                    ),
                    IF ( [CRank] >= 10, [CQuantity], 0 )
                ),
                ALL ( Companies )
            ),
            BLANK ()
        )
    )

5. Create a visual, filter "Top10" with "is not blank".RankX - Trying to create table that displays dynamic top 10 with an other group2.jpg

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Notes: 

1. Only top 9 and the total of all the left will be displayed when you apply the filter.

2. As you can see, the result of "Others" is correct.

3. I tried to modify the formula to fit your scenario. Please make some changes yourself.

 

Best Regards!

Dale

 

 

 

Community Support Team _ Dale
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
v-jiascu-msft
Employee
Employee

Hi @nalanis,

 

Could you please mark the proper answer as solution or share the solution if it's convenient for you? That will be a big help to the others.

 

Best Regards!
Dale

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
v-jiascu-msft
Employee
Employee

Hi @nalanis,

 

Did you apply any filters in this visual. It should show up all the companies. 

 

RankX - Trying to create table that displays dynamic top 10 with an other group.jpg

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

You missed a parameter of your formula.

Top10 =
IF (
    Sales[Rank (Coord_Company)] <= 10,
    Sales[Sum of CY Sales],
    IF (
        HASONEVALUE ( Sales[Coord Company] ),
        IF (
            VALUES ( Sales[Coord Company] ) = "Others",
            SUMX (
                FILTER ( ALL ( Sales[Coord Company] ), Sales[Rank (Coord_Company)] > 10 ),
                Sales[Sum of CY Sales]
            ),"missed"
        )
    )
)

Do you want show up the top 9 companies and "Others" and ignore the rank of "Others"?

Try this formula and filter the Top10 in the visual level filter with "is not blank".

Top10 =
IF (
    Sales[Rank (Coord_Company)] <= 10,
    Sales[Sum of CY Sales],
    IF (
        HASONEVALUE ( Sales[Coord Company] ),
        IF (
            VALUES ( Sales[Coord Company] ) = "Others",
            SUMX (
                FILTER ( ALL ( Sales[Coord Company] ), Sales[Rank (Coord_Company)] > 10 ),
                Sales[Sum of CY Sales]
            ),
blank() ) ) )

Best Regards!

Dale

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

Hi Dale,

 

I would like to display top 10 and then everything else wrapped up in "Other" without a ranking. I applied your second formula but am still missing the "Other" group. I think I know the problem though. In my coordinating company column data I do not have an "Other" listed so it isn't returning anything. So what I need to do is convert the Coord Company to a new column and create an entry of "Other". However, how would I go about doing that?

 

I created a rank measure with the following syntax: Rank (Agency) = IF(HASONEVALUE(Sales[Agency]),RANKX(ALL(Sales[Agency]),CALCULATE([CY Sales])))

 

Is there a way I can apply this measure to create an "Other" group?

 

Below are my results from applying the second formula.

 

Capture.PNG

 

Here are my filters as well.

Capture1.PNG

 

Thank you

 

 

Hi @nalanis,

 

You are right. No "Others" exists. That's the cause. 

1. Create a new table for all the Companies.

Companies =
UNION (
    FILTER (
        DISTINCT ( VALUES ( Sales[Coord Company] ) ),
        ISBLANK ( [Coord Company] ) = FALSE ()
    ),
    { "Others" }
)

2. Create a relationship between "Sales" and "Companies".

3. Create a new measure of Ranks.

RankxCompany =
RANKX (
    ALL ( 'Companies'[Coord Company] ),
    CALCULATE ( SUM ( Sales[CY Sales] ) )
)

4. Create a measure "Top10".

Top10 =
VAR ComRank = [RankxCompany]
RETURN
    IF (
        ComRank < 10,
        SUM ( Sales[CY Sales] ),
        IF (
            MIN ( 'Companies'[Coord Company] ) = "Others",
            CALCULATE (
                SUMX (
                    SUMMARIZE (
                        'Companies',
                        Companies[Coord Company],
                        "CQuantity", SUM ( Sales[CY Sales] ),
                        "CRank", RANKX (
                            ALL ( Companies[Coord Company] ),
                            CALCULATE ( SUM ( Sales[CY Sales] ) )
                        )
                    ),
                    IF ( [CRank] >= 10, [CQuantity], 0 )
                ),
                ALL ( Companies )
            ),
            BLANK ()
        )
    )

5. Create a visual, filter "Top10" with "is not blank".RankX - Trying to create table that displays dynamic top 10 with an other group2.jpg

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Notes: 

1. Only top 9 and the total of all the left will be displayed when you apply the filter.

2. As you can see, the result of "Others" is correct.

3. I tried to modify the formula to fit your scenario. Please make some changes yourself.

 

Best Regards!

Dale

 

 

 

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

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.