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
cmaloyb
Helper II
Helper II

Count TOP N for each Legend items that are Displayed on Graph

I am trying to create a card that will display the number of Top N items based on a category. Please consider the bar graph below.

NumberOfMaintJobsByEquipmentAndEquipmentResponsibility.JPG

 

I would like to display two Card visuals above the chart that gives a total of the Top 5 Equipment that has the most maintenance jobs. This is the table (partial) used to create this visual along with the filters:

Only partial data.Only partial data.Visual level filter. No Page or Report filters.Visual level filter. No Page or Report filters.

The desired result on each card would total up the number of maintenance jobs pertaining to each Equipment Responsibility. The Aerospace Engineer card would display 144 whereas the Electrical Engineer card would display 230. I would like for this to be dynamic as well if there were to have slicers on the report (Airplane type from a future data table). I created a card using the Count of Job Number field and filtering that visual for Top 5 Count of Job number and then by Equipment Responsibility, however it will total the top 5 Electrical Engineer job number's, for example. 

 

I have tried writing a DAX formula, but to be fairly honest, I'm having trouble understanding the TOPN function and am even wondering if I'm even going the right direction.

1 ACCEPTED SOLUTION
Icey
Community Support
Community Support

Hi @cmaloyb ,

 

Based on my test, you may need to filter TableName[Equipment Responsibility] inside the measure expression.

Top 5 Equipment - Aerospace Engineer =
SUMX (
    FILTER (
        TOPN (
            5,
            ADDCOLUMNS (
                SUMMARIZE (
                    TableName,
                    TableName[Equipment],
                    TableName[Equipment Responsibility]
                ),
                "@Count", CALCULATE ( DISTINCTCOUNT ( TableName[Job Number] ) )
            ),
            [@Count]
        ),
        [Equipment Responsibility] = "Aerospace Engineer"
    ),
    [@Count]
)
Top 5 Equipment - Electrical Engineer =
SUMX (
    FILTER (
        TOPN (
            5,
            ADDCOLUMNS (
                SUMMARIZE (
                    TableName,
                    TableName[Equipment],
                    TableName[Equipment Responsibility]
                ),
                "@Count", CALCULATE ( DISTINCTCOUNT ( TableName[Job Number] ) )
            ),
            [@Count]
        ),
        [Equipment Responsibility] = "Electrical Engineer"
    ),
    [@Count]
)

Icey_0-1653292607940.png

 

 

Best Regards,

Icey

 

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

7 REPLIES 7
tamerj1
Super User
Super User

Hi @cmaloyb 
Please try

Top 5 Engineers =
SUMX (
    TOPN (
        5,
        ADDCOLUMNS (
            VALUES ( TableName[Equipment Responsibilty] ),
            "@Count", CALCULATE ( DISTINCTCOUNT ( TableName[Job Number] ) )
        ),
        [@Count]
    ),
    [@Count]
)
Top 5 Equipment =
SUMX (
    TOPN (
        5,
        ADDCOLUMNS (
            VALUES ( TableName[Equipment] ),
            "@Count", CALCULATE ( DISTINCTCOUNT ( TableName[Job Number] ) )
        ),
        [@Count]
    ),
    [@Count]
)

 

The second DAX Function seems to give me the correct total, however when filtering Engineer Responsibility, it give the sum of the top 5 for that selected Engineer Responsibility instead of the 3 that are displayed on the visual. Below, I have provided an idea of what I would potentially like for my card visuals to read.NOTE: The circled Card visuals are just static numbers for the sake of example.NOTE: The circled Card visuals are just static numbers for the sake of example.

 

 

Hi @cmaloyb 
Would you please explain in further details?

When using this code.....

Top 5 Equipment =
SUMX (
    TOPN (
        5,
        ADDCOLUMNS (
            VALUES ( TableName[Equipment] ),
            "@Count", CALCULATE ( DISTINCTCOUNT ( TableName[Job Number] ) )
        ),
        [@Count]
    ),
    [@Count]
)

I was able to get "Top 5 Equipment" total of 374.

 

However, when I use "Equipment Responsibility" visual level filter on the "Top 5 Equipment" card, it filters for the TOP5 of the "Equipment Responsibility" that is filtered for. 

 

For example, if I filter "Equipement Responsibility on the the card for "Aerospace Engineer", I get 202, which is the count of the top 5 Aerospace equipment related jobs.  

Incorrect.Incorrect.

 

I am looking to have this filter only provide the count of what is displayed on the top 5 visual. The card should be 144.

 

Icey
Community Support
Community Support

Hi @cmaloyb ,

 

Based on my test, you may need to filter TableName[Equipment Responsibility] inside the measure expression.

Top 5 Equipment - Aerospace Engineer =
SUMX (
    FILTER (
        TOPN (
            5,
            ADDCOLUMNS (
                SUMMARIZE (
                    TableName,
                    TableName[Equipment],
                    TableName[Equipment Responsibility]
                ),
                "@Count", CALCULATE ( DISTINCTCOUNT ( TableName[Job Number] ) )
            ),
            [@Count]
        ),
        [Equipment Responsibility] = "Aerospace Engineer"
    ),
    [@Count]
)
Top 5 Equipment - Electrical Engineer =
SUMX (
    FILTER (
        TOPN (
            5,
            ADDCOLUMNS (
                SUMMARIZE (
                    TableName,
                    TableName[Equipment],
                    TableName[Equipment Responsibility]
                ),
                "@Count", CALCULATE ( DISTINCTCOUNT ( TableName[Job Number] ) )
            ),
            [@Count]
        ),
        [Equipment Responsibility] = "Electrical Engineer"
    ),
    [@Count]
)

Icey_0-1653292607940.png

 

 

Best Regards,

Icey

 

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

Thank you. This worked. Turns out we needed to add the filter to the DAX equation.

@cmaloyb 

Not sure if I fully understand but you may try

Top 5 Equipment =
SUMX (
    TOPN (
        5,
        ADDCOLUMNS (
            SUMMARIZE (
                TableName,
                TableName[Equipment],
                TableName[Equipment Responsibility]
            ),
            "@Count", CALCULATE ( DISTINCTCOUNT ( TableName[Job Number] ) )
        ),
        [@Count]
    ),
    [@Count]
)

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.

Top Solution Authors