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
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
Employee
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
Employee
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
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.