cancel
Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

Reply
badger123
Resolver I
Resolver I

TopN and 'Other' with date filter measure

Hello,

 

I'm trying to calculate top n and 'other'. I've followed these steps: https://www.minceddata.info/2018/06/06/topsomething-and-all-the-rest-called-other/. This works (see my measure below) but I want to add another layer of complexity.

 

The goal is to have a line chart showing monthly values over the past 4 years for the top 5 categories and 'other' categories. However, I want the top 5 to be based on the category values over the past 3 months. Does that make sense? How can I achieve this? I'm have a date index for relative date filtering.

 

Top 5 categories = 
var top5 = CALCULATETABLE(TOPN(5,VALUES(categories[category]),CALCULATE(SUM('values'[value]))))
var other = ROW("Category", "Other")
var allTheRest = CALCULATE(SUM('values'[value]), EXCEPT(VALUES(categories[category]),top5))
var theUnion = UNION(top5,other)
return
SUMX(
    INTERSECT('Unrelated',theUnion)
    ,
    var currentIterator = 'Unrelated'[categories and other]
    return
    IF(
        'Unrelated'[categories and other] <> "Other"   
        ,CALCULATE(
            SUM('values'[value])
            ,'categories'[category] = currentIterator
        )
        ,allTheRest
    )
)

 

2 REPLIES 2
v-juanli-msft
Community Support
Community Support

Hi @badger123 

Do you want to get a bar chart as below:

Capture6.JPG

For every month, show all top 5 categories, others show as "others".

Or you want a visual as the link shown which only has month.

 

Best Regards

Maggie

Hi @v-juanli-msft ,

 

Thanks for the quick response. I want to create a line chart, not a bar chart. Please see below.

Except I don't want to each month to show the top 5 categories each month... I want the whole thing to be based on the top 5 based on the values over the most recent 3 months (i.e. in this case Dec 2019, Jan 2020, Feb 2020... or 46, 47, 47 in index terms)... if that makes sense? 

 

 
 

Capture.PNG

Helpful resources

Announcements
PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

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

Community News

Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

Dashboard in a day with date

Exclusive opportunity for Women!

Join us for a free, hands-on Microsoft workshop led by women trainers for women where you will learn how to build a Dashboard in a Day!

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors