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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. 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
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
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

Check out the February 2024 Power BI update to learn about new features.

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.