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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
willz06jw
Helper II
Helper II

Rank count of Appt Types w/ rank 11 and above listed as Other

Hi and thanks for reading,

 

Capture.JPG

 

 

I am trying to figure out how to:

1.  Rank a count of Appointment Types

2.  Create a bar graph that lists the top 10, then count up all of the rest and list as OTHER.

 

I am stuck at part 1.  I am trying to use RANKX and calculate COUNTX, but I am having a difficult time with the code (since I am a bit of a DAX novice).

 

Here is what I am using -- it does not work

Rank = RANKX(appointments,calculate(COUNTx(Appointments,Appointments[Appt Type]),filter(Appointments,Appointments[Appt Type]=EARLIER(Appointments[Appt Type]))),,DESC,Dense)

 

Thank you for your help,

Will

1 ACCEPTED SOLUTION
v-yulgu-msft
Microsoft Employee
Microsoft Employee

Hi @willz06jw,

 

Not very sure how you want to show "count up all of the rest and list as OTHER". Based on my assumption, I considered below two scenarios. In my test, the visual shows Top 3 records.

 

1. Create Rank via measure. And show "OTHER" in a card visual.

Rank =
RANKX (
    ALL ( Appointments[Appt Type] ),
    CALCULATE (
        COUNTROWS ( Appointments ),
        ALLEXCEPT ( Appointments, Appointments[Appt Type] )
    ),
    ,
    DESC,
    DENSE
)


Other = CALCULATE(COUNTROWS(Appointments),FILTER(Appointments,[Rank]>3))

1.PNG

 

2. Show "OTHER" in bar chart as well as the Top10 list.

 

If that is the case, you need to create some extra calculated tables.

New first calculated table and add a calculated column.

Appointments2 =
ADDCOLUMNS (
    SUMMARIZE (
        Appointments,
        Appointments[Appt Type],
        "count of appointment", COUNT ( Appointments[Appt Type] )
    ),
    "Rank", RANKX (
        Appointments,
        CALCULATE (
            COUNT ( Appointments[Appt Type] ),
            ALLEXCEPT ( Appointments, Appointments[Appt Type] )
        ),
        ,
        DESC,
        DENSE
    )
)

Sum =
IF (
    Appointments2[Rank] > 3,
    CALCULATE (
        SUM ( Appointments2[count of appointment] ),
        FILTER ( Appointments2, Appointments2[Rank] > 3 )
    ),
    CALCULATE (
        SUM ( Appointments2[count of appointment] ),
        ALLEXCEPT ( Appointments2, Appointments2[Appt Type] )
    )
)

4.PNG

 

New a second calculated table. Drag fields from this table to bar chart.

Appointments3 =
UNION (
    SELECTCOLUMNS (
        FILTER ( Appointments2, Appointments2[Rank] <= 3 ),
        "Appt Type", Appointments2[Appt Type],
        "Count appt", Appointments2[Sum]
    ),
    SELECTCOLUMNS (
        FILTER ( Appointments2, Appointments2[Rank] = MAX ( Appointments2[Rank] ) ),
        "Appt Type", "Other",
        "Count appt", Appointments2[Sum]
    )
)

5.PNG

2.PNG

 

Best regards,

Yuliana Gu

Community Support Team _ Yuliana Gu
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

1 REPLY 1
v-yulgu-msft
Microsoft Employee
Microsoft Employee

Hi @willz06jw,

 

Not very sure how you want to show "count up all of the rest and list as OTHER". Based on my assumption, I considered below two scenarios. In my test, the visual shows Top 3 records.

 

1. Create Rank via measure. And show "OTHER" in a card visual.

Rank =
RANKX (
    ALL ( Appointments[Appt Type] ),
    CALCULATE (
        COUNTROWS ( Appointments ),
        ALLEXCEPT ( Appointments, Appointments[Appt Type] )
    ),
    ,
    DESC,
    DENSE
)


Other = CALCULATE(COUNTROWS(Appointments),FILTER(Appointments,[Rank]>3))

1.PNG

 

2. Show "OTHER" in bar chart as well as the Top10 list.

 

If that is the case, you need to create some extra calculated tables.

New first calculated table and add a calculated column.

Appointments2 =
ADDCOLUMNS (
    SUMMARIZE (
        Appointments,
        Appointments[Appt Type],
        "count of appointment", COUNT ( Appointments[Appt Type] )
    ),
    "Rank", RANKX (
        Appointments,
        CALCULATE (
            COUNT ( Appointments[Appt Type] ),
            ALLEXCEPT ( Appointments, Appointments[Appt Type] )
        ),
        ,
        DESC,
        DENSE
    )
)

Sum =
IF (
    Appointments2[Rank] > 3,
    CALCULATE (
        SUM ( Appointments2[count of appointment] ),
        FILTER ( Appointments2, Appointments2[Rank] > 3 )
    ),
    CALCULATE (
        SUM ( Appointments2[count of appointment] ),
        ALLEXCEPT ( Appointments2, Appointments2[Appt Type] )
    )
)

4.PNG

 

New a second calculated table. Drag fields from this table to bar chart.

Appointments3 =
UNION (
    SELECTCOLUMNS (
        FILTER ( Appointments2, Appointments2[Rank] <= 3 ),
        "Appt Type", Appointments2[Appt Type],
        "Count appt", Appointments2[Sum]
    ),
    SELECTCOLUMNS (
        FILTER ( Appointments2, Appointments2[Rank] = MAX ( Appointments2[Rank] ) ),
        "Appt Type", "Other",
        "Count appt", Appointments2[Sum]
    )
)

5.PNG

2.PNG

 

Best regards,

Yuliana Gu

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

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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