The ultimate Microsoft Fabric, Power BI, Azure AI, and SQL learning event: Join us in Stockholm, September 24-27, 2024.
Save €200 with code MSCUST on top of early bird pricing!
Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started
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
Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.
Check out the August 2024 Power BI update to learn about new features.
User | Count |
---|---|
21 | |
19 | |
18 | |
15 | |
13 |
User | Count |
---|---|
41 | |
36 | |
22 | |
22 | |
17 |