Join us for an expert-led overview of the tools and concepts you'll need to pass exam PL-300. The first session starts on June 11th. See you there!
Get registeredPower BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.
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
Measure that I used is
Expected
Could anyone help in resolving this ?
Solved! Go to Solution.
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
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
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
)
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]
)
My Date table looks like
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
15 | |
11 | |
11 | |
10 | |
10 |
User | Count |
---|---|
19 | |
14 | |
13 | |
11 | |
8 |