Microsoft Fabric Community Conference 2025, March 31 - April 2, Las Vegas, Nevada. Use code FABINSIDER for a $400 discount.
Register nowGet inspired! Check out the entries from the Power BI DataViz World Championships preliminary rounds and give kudos to your favorites. View the vizzies.
I am creating a chart in Power BI that needs to show the highest Sellout value in a constant straight line on the Y axis. The X axis should represent months in "MM/YYYY" format, and the display should be limited to the last 12 months prior to the month filtered by the user, using the calculation group I already have implemented, called Last 12M. However, the Max Sellout measure, which calculates the highest Sellout value in the chart, currently does not respect the calculation group filter and shows all months in the period.
My question is: How can I adjust the Max Sellout measure so that it respects the last 12 months limitation when used in the chart, considering that the Last 12M calculation group is active, so that the Max Sellout line in the chart represents the highest Sellout value within the range of 12 months prior to the month selected in the slicer?
The measurements are below:
Max Sellout =
MAXX(
ALL('dCalendar (Aux)'[YEAR/MONTH],'dCalendar (Aux)'[IndexYearMonth]),
[Sellout]
)
The measure below is a calculation group and I am using it as a filter to show only the last 12 months prior to the year/month being filtered.
Last 12M =
VAR DateReference = MAX( 'dCalendário'[Date] )
VAR PreviousDate =
DATESINPERIOD(
'dCalendar (Aux)'[Date],
DateReference ,
-12,
MONTH
)
VAR Resul =
CALCULATE(
SELECTEDMEASURE(),
REMOVEFILTERS( 'dCalendar' ),
KEEPFILTERS( PreviousDate ),
USERELATIONSHIP( 'dCalendar'[Date], 'dCalendar (Aux)'[Date] )
)
RETURN
Resul
See the chart above. The columns are correctly returning only the values of the last 12 months. It is a simple measure SUM(fSales_Sellout[Amount]). However, the measure 'Max Sellout' is returning all months. I need the DAX measure to return values only for the months that the calculation group is filtering on.
Since you are calling
ALL('dCalendar (Aux)'[YEAR/MONTH],'dCalendar (Aux)'[IndexYearMonth])
within the measure you are overwriting any external filters on date.
In the measure below we are still calculating the maxSellout but we are only returning the result if it falls within the 12 month period. I think this should be ok, even with the effect of the calc group on it
VAR DateReference = MAX( 'dCalendário'[Date] )
VAR PreviousDate =
DATESINPERIOD(
'dCalendar (Aux)'[Date],
DateReference ,
-12,
MONTH
)
VAR maxSellout =
MAXX(
ALL('dCalendar (Aux)'[YEAR/MONTH],'dCalendar (Aux)'[IndexYearMonth]),
[Sellout]
)
RETURN
IF( MAX( 'dCalendar (Aux)'[Date] ) in PreviousDate, maxSellout )
Well done, tank you!
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code FABINSIDER for a $400 discount!
Check out the February 2025 Power BI update to learn about new features.
User | Count |
---|---|
19 | |
12 | |
10 | |
9 | |
9 |
User | Count |
---|---|
17 | |
14 | |
12 | |
10 | |
9 |