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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
ShrimpSurf
Helper II
Helper II

Simple DAX Time Filter

I want to display a bar chart for revenue so when the user select June, 2021 the chart would only show six months.  If they choose December, 2021, then all twelve months are shown.  I have filters for both month and year.  Any help would be greatly appreciated.

1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

@ShrimpSurf I'm fairly certain that you are going to want a disconnected date table for your slicer. Then you can compare the value selected (MAX or SELECTEDVALUE) with the MAX of the actual date table in the axis of your chart visual and determine whether to return a value in your measure or BLANK().


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

3 REPLIES 3
Ashish_Mathur
Super User
Super User

Hi,

See if my solution here helps - Flex a Pivot Table to show data for x months ended a certain user defined month.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
AllisonKennedy
Super User
Super User

@ShrimpSurf  This is not exactly what you're looking for, but may give you some ideas and inspiration: https://excelwithallison.blogspot.com/2021/09/power-bi-forecasting-with-irregular.html 

 

If you share sample data (upload to OneDrive and share link) we can provide more specific measures and help for you, but you'll need to either generate a parameter table OR somehow build into the measure a condition that tells Power BI whether to display 6 months or 12 months, and accounts for all years in your data model. 

 

Parameter table would be best I think, so basically as @Greg_Deckler  said, a disconnected table with no relationships to your DimDate or data model that has:

 

Date | Number Months to Display

June 30, 2021 | 6

December 31, 2021 | 12

June 30, 2022 | 6

....

 

Then create a DAX measure that uses the parameter table to manipulate the measure: 

Filtered Measure =
VAR _startDate = SELECTEDVALUE (Parameter[Date] )

VAR _duration = SELECTEDVALUE Parameter[Number Months to Display] )

RETURN 
CALCULATE ( [Measure] , DATESINPERIOD( DimDate[Date], _startDate, -1*  _duration, Month)


Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

Greg_Deckler
Super User
Super User

@ShrimpSurf I'm fairly certain that you are going to want a disconnected date table for your slicer. Then you can compare the value selected (MAX or SELECTEDVALUE) with the MAX of the actual date table in the axis of your chart visual and determine whether to return a value in your measure or BLANK().


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.