Guille López
Guille López

Reputation: 53

Power BI: Column chart with both top and bottom

I'm trying to get in the same bar chart both the highest TOPN and the bottom TOPN in a way that resembles this graph:

enter image description here

But so far, no luck. I'm using DIM_Brand'[Brand] as category and FACT_Project_Portfolio[On-Shelf (days)] as values. My first reasoning was to create both measures seperately and add them to my chart. As an example for highest topN:

Top_4_Brands_On_Shelf_Days = 
VAR Top_4_Brands = TOPN(
    4, 
    SUMMARIZE(
        'DIM_Brand', 
        'DIM_Brand'[Brand],
        "Total On-Shelf Days", SUM(FACT_Project_Portfolio[On-Shelf (days)])
    ),
    [Total On-Shelf Days], DESC
)
RETURN
    SUMX(Top_4_Brands, [Total On-Shelf Days])

But not only I can't bring both measures on the same Y-axis; it doesn't even return the TOP4 by itself (while it works properly if I use the same DAX code to create a new table, so I guess I'll have to make use of that).

Upvotes: 0

Views: 276

Answers (2)

Guille López
Guille López

Reputation: 53

I solved it by creating a new table instead of trying to join two measures under the same axis. Also added color and label.


Top_Bottom_Column = 
VAR Top_Brands = 
    TOPN(
        4,
        SUMMARIZECOLUMNS(
            'DIM_Brand'[Brand],
            "Total On-Shelf Days", SUM(FACT_Project_Portfolio[On-Shelf (days)])
        ),
        [Total On-Shelf Days], DESC
    )
VAR Bottom_Brands = 
    TOPN(
        4,
        SUMMARIZECOLUMNS(
            'DIM_Brand'[Brand],
            "Total On-Shelf Days", SUM(FACT_Project_Portfolio[On-Shelf (days)])
        ),
        [Total On-Shelf Days], ASC
    )
VAR Top_Bottom_Union = UNION(Top_Brands, Bottom_Brands)
RETURN
    ADDCOLUMNS(
        Top_Bottom_Union,
        "Color", IF(RANKX(Top_Bottom_Union, [Total On-Shelf Days], , ASC) > COUNTROWS(Top_Bottom_Union) - 4, "Pink", "Orange"),
        "Performance", IF(RANKX(Top_Bottom_Union, [Total On-Shelf Days], , ASC) > COUNTROWS(Top_Bottom_Union) - 4, "Least performance", "Best performance")
    )

Upvotes: 0

Amira Bedhiafi
Amira Bedhiafi

Reputation: 1

I ranked all your brands based on the quantity, both from highest to lowest and lowest to highest.

I filtered this ranked list to include only the top 3 and bottom 3 brands.

Then I combine these subsets into a new table.

TopBottom3Brands = 
VAR Top3 = TOPN(3, ALL('MyTable'), 'MyTable'[Quantity], DESC)
VAR Bottom3 = TOPN(3, ALL('MyTable'), 'MyTable'[Quantity], ASC)
RETURN
UNION(Top3, Bottom3)

Here is my sample data :

enter image description here

enter image description here

enter image description here

Upvotes: 1

Related Questions