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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
CCmuffin
Frequent Visitor

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, @CCmuffin 

 

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.

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.


Visit my LinkedIn page by clicking here.


Schedule a meeting with me to discuss further by clicking here.

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
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.