Forum Discussion
Rai_Lomarques
Helper II
1 year agomonths with dynamic axis
I need to create a physical table in Power BI containing the last 12 months prior to the month that is being filtered in the data segmentation and at the end of this table I need to have an average s...
Anonymous
1 year agoNot applicable
Here I create a set of sample:
Then add a new table:
Calendar =
UNION (
SUMMARIZE (
SELECTCOLUMNS (
'Table',
"YEAR_MONTH", FORMAT ( 'Table'[Month/Date], "MM/YYYY" ),
"Date",
CALCULATE (
MIN ( 'Table'[Month/Date] ),
FILTER (
ALLSELECTED ( 'Table' ),
MONTH ( 'Table'[Month/Date] ) = MONTH ( EARLIER ( 'Table'[Month/Date] ) )
&& YEAR ( 'Table'[Month/Date] ) = YEAR ( EARLIER ( 'Table'[Month/Date] ) )
)
)
),
[YEAR_MONTH],
[Date]
),
ADDCOLUMNS (
{ "Average" },
"Date",
DATE ( YEAR ( MAX ( 'Table'[Month/Date] ) ), MONTH ( MAX ( 'Table'[Month/Date] ) ) + 1, 1 )
)
)
Select the YEAR_MONTH Column and click the Sort by column in the Column tools pane then select [Date]:
Finally add a measure:
MEASURE =
VAR _currentYear =
YEAR ( SELECTEDVALUE ( 'Calendar'[Date] ) )
VAR _currentMonth =
MONTH ( SELECTEDVALUE ( 'Calendar'[Date] ) )
RETURN
IF (
SELECTEDVALUE ( 'Calendar'[YEAR_MONTH] ) <> "Average",
CALCULATE (
SUM ( 'Table'[Values] ),
FILTER (
ALLSELECTED ( 'Table' ),
YEAR ( 'Table'[Month/Date] ) = _currentYear
&& MONTH ( 'Table'[Month/Date] ) = _currentMonth
)
),
CALCULATE ( AVERAGE ( 'Table'[Values] ), ALLSELECTED ( 'Table' ) )
)
The result is as follow:
Best Regards
Zhengdong Xu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.