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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
azadthakur
Frequent Visitor

TOPN and Others with other columns as well

Hello Team,

I’ve successfully created a measure to calculate the Top N brands by sales and the "Others" category based on a Top N slicer. However, I've encountered an issue: when I add another column, such as "Year," to the matrix visual, the Top N brands vary across different years. I need the Top N brands to remain consistent across all years, regardless of the year filter.

 

Top N Retail Sales or Units =
VAR TopNValue1 = SELECTEDVALUE('TopN'[TopN])
VAR SalesorUnits = SELECTEDVALUE('Retail Sales or Units'[Metric])
VAR TopBrand =
    TOPN(
        TopNValue1,
        ALLSELECTED(TopNBrands),
        SWITCH (
            SalesorUnits,
            "Units", [Sum of Units],
            "Sales", [Sum of Sales],
            BLANK ()
        )
    )

VAR AllRetailSalesUnits =
    CALCULATE(
        SWITCH (
            SalesorUnits,
            "Units", [Sum of Units],
            "Sales", [Sum of Sales],
            BLANK ()
        ),
        ALLSELECTED(TopNBrands)
    )

VAR OtherRetailSalesUnits =
    AllRetailSalesUnits -
    CALCULATE(
        SWITCH (
            SalesorUnits,
            "Units", [Sum of Units],
            "Sales", [Sum of Sales],
            BLANK ()
        ),
        TopBrand
    )

VAR TopNRetailsSalesUnits =
    CALCULATE(
        SWITCH (
            SalesorUnits,
            "Units", [Sum of Units],
            "Sales", [Sum of Sales],
            BLANK ()
        ),
        KEEPFILTERS(TopBrand)
    )

VAR CurrentBrand = SELECTEDVALUE(TopNBrands[Brand])

RETURN
    IF(
        CurrentBrand = "Other",
        OtherRetailSalesUnits,
        TopNRetailsSalesUnits
    )" I am getting below result when i am selecting topn as 5 in slicer with onl brands
 
top5.png
 
but when i drag fiscal year also here, it is giving me different brands across each year like below"
 
top5_.png
 
and i need same topn brands across any year, it should not be different top brands for every year.
2 REPLIES 2
bhanu_gautam
Super User
Super User

@azadthakur , To ensure that the Top N brands remain consistent across all years, you need to modify your DAX measure to calculate the Top N brands without considering the year filter. This can be achieved by using the ALL function 

 

Top N Retail Sales or Units =
VAR TopNValue1 = SELECTEDVALUE('TopN'[TopN])
VAR SalesorUnits = SELECTEDVALUE('Retail Sales or Units'[Metric])

-- Calculate the Top N brands without considering the year filter
VAR TopBrand =
TOPN(
TopNValue1,
ALL(TopNBrands),
SWITCH (
SalesorUnits,
"Units", [Sum of Units],
"Sales", [Sum of Sales],
BLANK ()
)
)

-- Calculate the total sales or units for all brands without considering the year filter
VAR AllRetailSalesUnits =
CALCULATE(
SWITCH (
SalesorUnits,
"Units", [Sum of Units],
"Sales", [Sum of Sales],
BLANK ()
),
ALL(TopNBrands)
)

-- Calculate the sales or units for the "Other" category
VAR OtherRetailSalesUnits =
AllRetailSalesUnits -
CALCULATE(
SWITCH (
SalesorUnits,
"Units", [Sum of Units],
"Sales", [Sum of Sales],
BLANK ()
),
TopBrand
)

-- Calculate the sales or units for the Top N brands
VAR TopNRetailsSalesUnits =
CALCULATE(
SWITCH (
SalesorUnits,
"Units", [Sum of Units],
"Sales", [Sum of Sales],
BLANK ()
),
KEEPFILTERS(TopBrand)
)

-- Get the current brand
VAR CurrentBrand = SELECTEDVALUE(TopNBrands[Brand])

RETURN
IF(
CurrentBrand = "Other",
OtherRetailSalesUnits,
TopNRetailsSalesUnits
)

 




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






Hi @bhanu_gautam , thanks for replying on this. My fiscal year column is in different table. I tried your formula but result is same the topn brands is different for each year.

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.