Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Dodgywheel
Frequent Visitor

Date Slicer that show last N Months including current month

HI,

I have a report to look at the last N months of data, but want to include current month, the filter for selecting the amount of months needs to be simple like the standard slicer 

Slicer.JPG

Does anyone know a way to do this .

 

Thanks

1 ACCEPTED SOLUTION

Hi @Dodgywheel,

You can create a what-if parameter table with numeric values, then use it as slicer to choose month numbers that you want to be filtered.
Then you can write a measure formula to extract selected value to compare current table values and return tag. After these states, you can use this measure on the 'visual level filter' to filter records.

Measure =
VAR selected =
    MAX ( Selector[Number] )
VAR currDate =
    MAX ( table[date] )
RETURN
    IF (
        currDate
            IN CALENDAR (
                DATE ( YEAR ( currDate ), MONTH ( currDate ) - selected, DAY ( currDate ) ),
                currDate
            ),
        "Y",
        "N"
    )

Notice: selector means the what-if table that used to selected month numbers.
Regards,

Xiaxoin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

6 REPLIES 6
v-shex-msft
Community Support
Community Support

Hi @Dodgywheel,

What type of 'include current month' you mean? Does force add the current month to your calculation range or start/end with the current month? Please share more detail information to help us clarify your requirement.

How to Get Your Question Answered Quickly 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Hi @v-shex-msft , 

So for example , my graph currently has the slicer set to show Last 6 months,  so the data it shows are as below

6month.JPG

As you can see the months covered are DEC - MAY inc. what i would like is to show JAN - JUN as the last 6 months , so the current month is included, i know i can do this with a slicer selecting dates in between the two months but for ease of use when presenting data i want to keep the select last N months slicer.

 

Thanks

Dale

Hi @Dodgywheel,

You can create a what-if parameter table with numeric values, then use it as slicer to choose month numbers that you want to be filtered.
Then you can write a measure formula to extract selected value to compare current table values and return tag. After these states, you can use this measure on the 'visual level filter' to filter records.

Measure =
VAR selected =
    MAX ( Selector[Number] )
VAR currDate =
    MAX ( table[date] )
RETURN
    IF (
        currDate
            IN CALENDAR (
                DATE ( YEAR ( currDate ), MONTH ( currDate ) - selected, DAY ( currDate ) ),
                currDate
            ),
        "Y",
        "N"
    )

Notice: selector means the what-if table that used to selected month numbers.
Regards,

Xiaxoin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.
Anonymous
Not applicable

No this is way too much work and maintenance. Surely Power BI funcitonality needs to cater - this is very straight forward . Most companies will want to see what is performance of last N months and include current month to date. So today is 20 April, I want to see APRIL mtd totals, and then the last N full months for comparison. Much like the DAYS relative date fiter, just add in a INCLUDE THIS MONTH tick box. 😉 simple.

amitchandak
Super User
Super User

@Dodgywheel , When you use date slicer of visual level or page level you have the option to include today.

 

You can add this month /MTD data to the measure

Add this

MTD QTY forced=
var _max = today()
var _min = eomonth(today(),-1)+1
return
calculate(Sum('order'[Qty]),filter(all('Date'),'Date'[Date]<=_max && 'Date'[Date]>=_min))

Hi @amitchandak 

I have the filter set to include Today but it doesn't show current month, my measure that i am graphing per month is 

OEE % = 'pro vw_ProductionOEE'[OEE Loss] * 100  
Is the below correct for how it fits with the formula you shared or is it a seperate new measure. 
MTD QTY forced=
var _max = today()
var _min = eomonth(today(),-1)+1
return
calculate('pro vw_ProductionOEE'[OEE Loss] * 100  ),filter(all('Date'),'Date'[Date]<=_max && 'Date'[Date]>=_min))
 
I am a novice to Power BI so still teaching myself slowly
Thanks for the help
Dale

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.