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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Anonymous
Not applicable

Annual sum ranking of products

Hi, I've been stuck with this issue for a few weeks.

 

I am making an annual search sum ranking of products.

There are dozens of categories and thousands of products.

I record the number of searches and rankings of all products every month.

 

CCmuffin_0-1646618178673.png

There is also another table that categorizes all products.

 

I want to get a ranking of the category every month, with data from that point to 1 year before then.

There are two criteria.

1. Every month, check if there is at least one product in rank 200 or more in each category.

 The number of times per year is summed up. It will be up to 12 times.

2. By category, add up all the top 200 searches in the past year.

 

I have no idea how to start. Please help.

4 REPLIES 4
v-zhangti
Community Support
Community Support

Hi, @Anonymous 

 

Based on your description, I briefly simulated some data.
1. Every month, check if there is at least one product in each category that is ranked 3 or higher.
2. By category, add up all the top 3 searches in the past year.

Please check if it meets your needs, and reply to inform if you have additional requests.

Measure =
CALCULATE (
    COUNT ( 'Table'[Product] ),
    FILTER (
        ALL ( 'Table' ),
        [rank] <= 3
            && [month] = SELECTEDVALUE ( 'Table'[month] )
            && [category] = SELECTEDVALUE ( 'Table'[category] )
    )
)
Measure2 =
VAR N1 =
    CALCULATE (
        SUM ( 'Table'[searches] ),
        FILTER (
            ALL ( 'Table' ),
            [category] = SELECTEDVALUE ( 'Table'[category] )
                && [rank] <= 3
        )
    )
VAR N2 =
    CALCULATE (
        N1,
        DATESINPERIOD ( 'Table'[Date], LASTDATE ( 'Table'[Date] ), -12, MONTH )
    )
RETURN
    N2

vzhangti_0-1646812855126.png

Please check the attachment.

 

Best Regards,

Community Support Team _Charlotte

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

Anonymous
Not applicable

Wow. It's pretty close to what I wanted.

but I need a little modification.

 

 

 

Measure = 
CALCULATE (
    COUNTA( 'Data'[product]),
    FILTER (
        ALL ( 'Data'),
        [rank] <= 200
            && [date] = DATESINPERIOD ('Data'[date], LASTDATE ( 'Data'[date] ), -12, MONTH )
            && [category] = SELECTEDVALUE ( 'Data'[category] )
    )
)

 

 

 

Measure 1 is to add +1 to the category if any of the products are in the top 200.

So I changed 'COUNT' to 'COUNTA' and also limited the period in an year.

Why is this code not working?

 

I attatched my BI file.

https://1drv.ms/u/s!AjtR6aAtuhbt_HNH08m1B9sxze6X?e=fJocoY

thank you.

Jihwan_Kim
Super User
Super User

Hi,

I am not sure if I understood your question correctly, but please check the below picture and the attached pbix file.

All measures are in the attached pbix file.

 

Picture1.png

 

Number of search: =
SUM('Search'[Search] )
 
Number of search last 12 months: =
CALCULATE (
[Number of search:],
DATESINPERIOD ( Dates[Date], LASTDATE ( Dates[Date] ), -12, MONTH )
)
 
Number of search by product only top 5: =
VAR categorymonthtable =
FILTER (
SUMMARIZE (
ALL ( 'Search' ),
Dates[Month & Year],
'Product'[Category],
'Product'[Product]
),
Dates[Month & Year] = MAX ( Dates[Month & Year] )
)
RETURN
CALCULATE (
[Number of search last 12 months:],
KEEPFILTERS (
TOPN ( 5, categorymonthtable, [Number of search last 12 months:], DESC )
)
)

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.
Anonymous
Not applicable

This is not what I was looking for, but it's a good example to practice. I learned a lot from this.
The keymeasures trick is amazing. It will be useful.

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

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