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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

How To Determine Top Ranking Sales Category for a Specific Time Period

Hello everyone,

 

I am having some trouble with filtering the top ranking category (by sales) for a specific time period. From previous tips on this forum, the top-ranking category for all sales can be found by:

Category Top =
VAR _A =
    FILTER (
        ADDCOLUMNS (
            'Sales',
            "Rank",
                RANKX (
                    ALLSELECTED ( 'Sales'[Category] ),
                    CALCULATE ( SUM ( 'Sales'[Sales Amount] ) ),
                    ,
                    DESC,
                    DENSE
                )
        ),
        [Rank] = 1
    )
RETURN
    MAXX ( _A, [Category] )

 

I am having trouble filtering this down for a specific time period (say 7 days).  To attempt to tackle this, I have tried replacing:

 

CALCULATE ( SUM ( 'Sales'[Sales Amount] ) )

with 

CALCULATE ( SUM ( 'Sales'[Sales Amount] ), DATESINPERIOD('Sales'[DATE], TODAY(), -7, DAY)

 

But this doesn't seem to produce the results I am looking for. 

 

Any tips? 

 

 

1 ACCEPTED SOLUTION
VahidDM
Super User
Super User

HI @Anonymous 

 

Try this:

Category Top =
VAR _A =
    FILTER (
        ADDCOLUMNS (
            'Sales',
            "Rank",
                RANKX (
                    'Sales',
                    CALCULATE (
                        SUM ( 'Sales'[Sales Amount] ),
                        DATESINPERIOD ( 'Sales'[DATE], TODAY (), -7, DAY )
                    ),
                    ,
                    DESC,
                    DENSE
                )
        ),
        [Rank] = 1
    )
RETURN
    MAXX ( _A, [Category] )

 

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
LinkedIn: 
www.linkedin.com/in/vahid-dm/

 

 

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Thanks VahidDM

VahidDM
Super User
Super User

HI @Anonymous 

 

Try this:

Category Top =
VAR _A =
    FILTER (
        ADDCOLUMNS (
            'Sales',
            "Rank",
                RANKX (
                    'Sales',
                    CALCULATE (
                        SUM ( 'Sales'[Sales Amount] ),
                        DATESINPERIOD ( 'Sales'[DATE], TODAY (), -7, DAY )
                    ),
                    ,
                    DESC,
                    DENSE
                )
        ),
        [Rank] = 1
    )
RETURN
    MAXX ( _A, [Category] )

 

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
LinkedIn: 
www.linkedin.com/in/vahid-dm/

 

 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.