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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
akoschinek
Frequent Visitor

Sales Amount by Year for the Top N and Other

I have a report, that shows the Top n Sub-Categories and Other by Sales Amount.

For the selection of the Top n i created a table with values from 1 to 10.

 

Select Top n = {1,2,3,4,5,6,7,8,9,10}

 

I created another table with the Sub-Categories + Other as follows:

 

Sub-Category and Other =

    UNION(

    DISTINCT(Orders[Sub-Category]),
    DATATABLE("Sub-Category",STRING,{{"Other"}})
    )

 

The calculation for the Top n + Other:

 

Top n Sub-Category =
VAR _TopnSubCategory =
    TOPN (
        SELECTEDVALUE('Select Top n'[Show Top n]),
        ALLSELECTED( 'Sub-Category and Other'),
        [Sum of Sales]
    )
VAR _AllSales =
    CALCULATE (
        [Sum of Sales],
        ALL ( 'Sub-Category and Other' )
    )
VAR _TopSalesTotal =
    CALCULATE (
        [Sum of Sales],
        _TopnSubCategory
    )
VAR _TopSales =
    CALCULATE (
        [Sum of Sales],
        KEEPFILTERS ( _TopnSubCategory )
    )
VAR _OtherSales = _AllSales - _TopSalesTotal
VAR _TopSubCategories =
    SELECTEDVALUE ( 'Sub-Category and Other'[Sub-Category] )
VAR _Result =
    IF (
        _TopSubCategories <> "Other",
        _TopSales,
        _OtherSales
    )
RETURN
_Result

 

This is the result for top 4 that i get and expected:

akoschinek_1-1672749986770.png

Now i want to get the Sales value by year for the top 4 and Other. But when i add the year it changes my filter context and i get the top 4 by year:

akoschinek_3-1672750191621.png

 

This is the result i am trying to achieve is the yearly Sales amount by the top 4 of the total Sales amount:

 

akoschinek_2-1672750039397.png

 

5 REPLIES 5
RekhaSikarwar
Regular Visitor

hi , did you reached to the solution. Actually i am having a same requirement. If yes, please do share the solution.

amitchandak
Super User
Super User

@akoschinek , refer if this approach can help

Power BI- TOPN with Others- https://youtu.be/I_TY4hVlzAE

 

https://goodly.co.in/top-n-and-others-power-bi/

Thank you for your response.

I actually used this approach to get the Top N and Others. 
What i can't get to work, to split this by year without getting the Top N by year, but the yearly amount of the Overall Top N and Others.

Thank you, i wasn't aware the WINDOW function had been added. 
But from what i can see i can get the top N Sub-Categories by year, instead of having the overall top N and then taking these and het their value per year.

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

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

Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.