Forum Discussion
Measure needs to be fine-tuned
- 3 months ago
Hi ArchStanton,
Hope you're doing well!
you just need to exclude the current calendar month from the ValidMonths variable before the MIN/MAX calculation runs.
Add a TODAY() reference to capture the current month, then filter it out from ValidMonths:
MinMaxMth =
VAR AllMonths =
CALCULATETABLE (
ADDCOLUMNS ( VALUES ( Date2[Mth] ), "Value", [Primary Topics] ),
ALLSELECTED ( 'Date2' )
)
VAR CurrentCalendarMonth =
FORMAT ( TODAY (), "MMM" )
VAR ValidMonths =
FILTER (
AllMonths,
NOT ISBLANK ( [Value] )
&& [Value] > 0
&& Date2[Mth] <> CurrentCalendarMonth
)
VAR MinMonth =
MAXX ( TOPN ( 1, ValidMonths, [Value], ASC, 'Date2'[Mth], ASC ), Date2[Mth] )
VAR MaxMonth =
MAXX ( TOPN ( 1, ValidMonths, [Value], DESC, 'Date2'[Mth], ASC ), Date2[Mth] )
VAR CurrentMonth =
SELECTEDVALUE ( Date2[Mth] )
RETURN
SWITCH (
TRUE (),
CurrentMonth = MinMonth, "MIN",
CurrentMonth = MaxMonth, "MAX",
BLANK ()
)
The key addition is CurrentCalendarMonth using FORMAT(TODAY(), "MMM"), which needs to match exactly the format your Mth column uses, if your column stores full month names like "June" rather than "Jun", just change the format string to "MMMM" accordingly.
Hi ArchStanton,
Hope you're doing well!
you just need to exclude the current calendar month from the ValidMonths variable before the MIN/MAX calculation runs.
Add a TODAY() reference to capture the current month, then filter it out from ValidMonths:
MinMaxMth =
VAR AllMonths =
CALCULATETABLE (
ADDCOLUMNS ( VALUES ( Date2[Mth] ), "Value", [Primary Topics] ),
ALLSELECTED ( 'Date2' )
)
VAR CurrentCalendarMonth =
FORMAT ( TODAY (), "MMM" )
VAR ValidMonths =
FILTER (
AllMonths,
NOT ISBLANK ( [Value] )
&& [Value] > 0
&& Date2[Mth] <> CurrentCalendarMonth
)
VAR MinMonth =
MAXX ( TOPN ( 1, ValidMonths, [Value], ASC, 'Date2'[Mth], ASC ), Date2[Mth] )
VAR MaxMonth =
MAXX ( TOPN ( 1, ValidMonths, [Value], DESC, 'Date2'[Mth], ASC ), Date2[Mth] )
VAR CurrentMonth =
SELECTEDVALUE ( Date2[Mth] )
RETURN
SWITCH (
TRUE (),
CurrentMonth = MinMonth, "MIN",
CurrentMonth = MaxMonth, "MAX",
BLANK ()
)
The key addition is CurrentCalendarMonth using FORMAT(TODAY(), "MMM"), which needs to match exactly the format your Mth column uses, if your column stores full month names like "June" rather than "Jun", just change the format string to "MMMM" accordingly.
Thanks, the works perfectly, its always obvious when you see the solution