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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
SR_BI
Frequent Visitor

Max Monthly Sales using MAXX TOPN Shows incorrect total

I have a matrix with Year and Month. I wish to add measure which will display the

1. Best Selling Month of Year

2. Sale value of the Best Selling Month.

While doing this exercise with MAXX and TOPN ,

the Grand Total displays correctly but values at year-month level displays incorrectly ( Highlighted in Orange ),

Expected 

  • 908941.83 in all rows of [Sales of Best Selling Month of the Year (MAXX-TOPN) for 2017  and 
  • December 2017 in all rows of [Best Selling Month of the Year (MAXX-TOPN)] for 2017

Measure that I used is 

Sales of Best Selling Month of the Year (MAXX-TOPN) =
MAXX(
     TOPN( 1, ALLSELECTED('Date'[Year Month]),[Sales Amount],DESC)
    ,[Sales Amount]
)
Best Selling Month of the Year (MAXX-TOPN) =
    MAXX(
        TOPN( 1, ALLSELECTED('Date'[Year Month]),[Sales Amount],DESC)
        ,[Year Month]
    )

 

SR_BI_0-1721459057702.png

 

Expected

SR_BI_1-1721459146320.png

Could anyone help in resolving this ?

1 ACCEPTED SOLUTION
OwenAuger
Super User
Super User

Hi @SR_BI 

Below is how I would suggest writing these measures.

In both measures, I suggest using PARALLELPERIOD to modify the 'Date' filter to be the smallest set of complete year(s) containing the original 'Date' filter.

 

Sales of Best Selling Month of the Year =
CALCULATE (
    MAXX ( VALUES ( 'Date'[Year Month] ), [Sales Amount] ),
    PARALLELPERIOD ( 'Date'[Date], 0, YEAR )
)
Best Selling Month of the Year =
CALCULATE (
    FIRSTNONBLANK ( TOPN ( 1, VALUES ( 'Date'[Year Month] ), [Sales Amount], DESC ), 0 ),
    PARALLELPERIOD ( 'Date'[Date], 0, YEAR )
)

 

The 1st measure doesn't need TOPN since MAXX already returns the single maximum value regardless of ties.

In the 2nd measure, I used FIRSTNONBLANK as an arbitrary tie-breaker (following a pattern in this article) rather than MAXX, but either MINX/MAXX or FIRSTNONBLANK/LASTNONBLANK would be valid.

 

Do these work as expected for you?

 

Regards


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
LinkedIn

View solution in original post

3 REPLIES 3
OwenAuger
Super User
Super User

Hi @SR_BI 

Below is how I would suggest writing these measures.

In both measures, I suggest using PARALLELPERIOD to modify the 'Date' filter to be the smallest set of complete year(s) containing the original 'Date' filter.

 

Sales of Best Selling Month of the Year =
CALCULATE (
    MAXX ( VALUES ( 'Date'[Year Month] ), [Sales Amount] ),
    PARALLELPERIOD ( 'Date'[Date], 0, YEAR )
)
Best Selling Month of the Year =
CALCULATE (
    FIRSTNONBLANK ( TOPN ( 1, VALUES ( 'Date'[Year Month] ), [Sales Amount], DESC ), 0 ),
    PARALLELPERIOD ( 'Date'[Date], 0, YEAR )
)

 

The 1st measure doesn't need TOPN since MAXX already returns the single maximum value regardless of ties.

In the 2nd measure, I used FIRSTNONBLANK as an arbitrary tie-breaker (following a pattern in this article) rather than MAXX, but either MINX/MAXX or FIRSTNONBLANK/LASTNONBLANK would be valid.

 

Do these work as expected for you?

 

Regards


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
LinkedIn

Thank you very much.

Yes Parallelperiod solution it works as expected . Learnt more about FIRSTNONBLANK usage 

 

Sales of BSM of Year (Cal-MAXX-PP) =

CALCULATE(

    MAXX( VALUES('Date'[Year Month]), [Sales Amount] ),

    PARALLELPERIOD('Date'[Date] , 0 , YEAR)

)

 

BSM of Year C-PP =

CALCULATE(

    FIRSTNONBLANK( TOPN(1,VALUES('Date'[Year Month]),[Sales Amount] , DESC), 0),

    PARALLELPERIOD( 'Date'[Date] , 0 , YEAR)

)

 

Also realized my mistake , Matrix Row filter was on Date[Year] and Date[Month] and Date[Month] was sorted by Date[Month Number].

Without Parallelperiod Time intelligence function , rewrote using VALUES

 

Fixed Sales of BSM of Year (C-MAXX-VALUES) =

CALCULATE(

    MAXX

    (

        ALLSELECTED( 'Date'[Year],'Date'[Month], 'Date'[Month Number] ),

        [Sales Amount]

    )

    , VALUES('Date'[Year])  -- Include Year Context @ Month/Year/GT Level

)

 

 

SR_BI_0-1721958385988.png

 

 

Used Rand to break ties in Topn

Fixed BSM of the Year (TOPN) =

VAR TopSalesBreakTies =

CALCULATETABLE(

        TOPN(1,

            ALLSELECTED('Date'[Year Month]),

            [Sales Amount],DESC, RAND(),DESC

        ),

        REMOVEFILTERS( 'Date'[Month], 'Date'[Month Number])

)

RETURN

    MINX(

        TopSalesBreakTies,

        [Year Month]

    )

SR_BI_1-1721958385993.png

 

 

 

SR_BI
Frequent Visitor

My Date table looks like

SR_BI_0-1721460578154.png

 

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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