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
Anonymous
Not applicable

Issue with applying filters to last X amount of months

Hi all,

 

Struggling with this one for a while.

 

Assuming I want to see monthly data from the last 6 months, using the relative date slicer. I have 2 options:
1. Last 6 months - This actually translates to last ~180 days. It returns the data of the last partial month, but it does not return the full data of the first month in the timeframe 

2. Last 6 calendar months - This returns full data of the previous 6 months, but nothing for the current partial month


I need to be able to have a filter on the page, that shows full data for months 1-5 + partial data for month 6 in the timeframe. 
The only workaround I found was to apply the Top 6 months/period to each visual separately. Not fun. 

Any ideas?
Thanks!

1 ACCEPTED SOLUTION
Anonymous
Not applicable

I have added this idea to the Ideas forum
https://ideas.powerbi.com/ideas/idea/?ideaid=bc643b1c-c626-eb11-8441-281878bda84d

This is something that should work out of the box, without any workarounds
Please vote!

Thanks



View solution in original post

6 REPLIES 6
v-jayw-msft
Community Support
Community Support

Hi @Anonymous ,

 

Good idea, already vote for it.

 

Best Regards,

jay

Community Support Team _ Jay
If this post helps, then please consider Accept it as the solution
to help the other members find it.
mahoneypat
Employee
Employee

You can write a measure expression like this to get your desired date range.

 

Prev Six Months =
VAR thisdate =
    MAX ( 'Date'[Date] )
VAR startdate =
    EOMONTH (
        thisdate,
        -7
    ) + 1
RETURN
    CALCULATE (
        [MinMaxDates],
        FILTER (
            ALL ( 'Date'[Date] ),
            'Date'[Date] <= thisdate
                && 'Date'[Date] >= startdate
        )
    )

 

Note you can also use a measure like to this to see which date range you are returning.  Use the name of this measure instead of [Total Sales] above and then replace with your final measure when you know you have the dates you want.

 

MinMaxDates = Min('Date'[Date]) & "-" & MAX('Date'[Date])
 
Regards,
Pat




Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Anonymous
Not applicable

Hi @mahoneypat

 

Thanks for your help. I am looking for a dynamic way, in which users that filter my report will be able to get any last x amount of months, including full data for complete months in the time range + data of the current month. 
For last 6 months, 5 full months + partial of month 6
For last 10 months, 9 full months + partial of month 10
ETC...

 

This can be achieved on a visual level, using Top 10 month, or top 6 month. But the "Top" functionality is not working on a page level.

Bottom line, the selection should be dynamic, not hardcoded in DAX

You can add a What-If Parameter to your report so people can choose the number of months, and then use the value from that in place of the "-7" in that measure.

Regards,

Pat

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Anonymous
Not applicable

I have added this idea to the Ideas forum
https://ideas.powerbi.com/ideas/idea/?ideaid=bc643b1c-c626-eb11-8441-281878bda84d

This is something that should work out of the box, without any workarounds
Please vote!

Thanks



Good idea.  Did it work for you and you can mark it as the solution?

Regards,

Pat

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


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.