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
pbiandt
Frequent Visitor

Date filter month and day

Is there a way to filter just the month and day (eg. Jan 1 - Mar 23 or Feb 15-Mar 15). I have data from past 10 years and would like to look at specific date ranges within the year for each year. So if one selects Mar 1-Mar 15 say, the data for each year will display the values between those dates.

 

Also, I'm looking for a visualization that would help me in displaying the average of a value over the last 10 years and whether the current year value is higher or lower (indicated with an arrow or color)? Any suggestions?

 

Thanks!

1 ACCEPTED SOLUTION

Hi @pbiandt ,

 

Sorry, I didn't fully understand you before.

I created a calendar table and used it as a slicer, then recreated the measure to calculate the sum.

sum_value = CALCULATE(SUM('data'[Amount]),FILTER(data,data[month_day]in VALUES(('date'[month_day]))))

The sample pbix has been updated

 

Best Regards,
Liang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

9 REPLIES 9
pbiandt
Frequent Visitor

Thanks @amitchandak and @Greg_Deckler for your help.

 

I've tried both your syntax but I'm still not getting the desired result.

My data consists of a table with ID and Birth Date. I have a date table linked to the birth date.

 

I would like a table that displays the distinct count of ID by Birth Year filtered by a date slicer such that only the month and day are considered in the date slicer. For example, if the slicer was between Feb 15-Mar 15, then the table would display the distinct count of ID for birth dates between those dates for each year.

@amitchandakIn your solution, I replaced the sum function with the distinctcount function but the filtering doesn't seem to be working.

 

Thanks @V-lianl-msft for your solution. However, your solution only works if the dates were within a particular month. It wouldn't work if the dates were between months (eg. Feb 15-Mar 15).

Hi @pbiandt ,

 

Sorry, I didn't fully understand you before.

I created a calendar table and used it as a slicer, then recreated the measure to calculate the sum.

sum_value = CALCULATE(SUM('data'[Amount]),FILTER(data,data[month_day]in VALUES(('date'[month_day]))))

The sample pbix has been updated

 

Best Regards,
Liang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi @pbiandt ,

 

Is this problem sloved?
If not, please let me know.

 

Best Regards,
Liang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

Sorry @V-lianl-msft and @Greg_Deckler I don't understand if the post has been solved.

 

I downloaded @V-lianl-msft file but the filter still depends on year, while @pbiandt looked to filter all of his years for the time period selected. This is what I need to do, meaning I have some dates in many years (2016 to 2020) and need to filter them based just on day and month, so if I choose from January, 1st to March, 19th it selects this period from all the years I have.

 

Maybe I didn't understand your solution, in this case please point me what I am missing.

 

Thank you very much

 

Nick 

@pbiandt 

Try with all

 

measure =
var _max = format(maxx('Date','Date'[Date]),"MMDD")
var _min = format(Minx('Date','Date'[Date]),"MMDD")

return
CALCULATE(SUM(Data[Amount]), FILTER(all('Date'), format('Date'[Date],"MMDD") >=_min && format('Date'[Date],"MMDD") <=_max ))

 

V-lianl-msft
Community Support
Community Support

Hi @pbiandt ,

 

1.You can format year, month, day, and then use them as slicers.

test_format.PNG

2.First, create a measure to calculate the average of the past few years

AVG_all_YEAR = 
VAR SUM_VALUE = CALCULATE(SUM(Sheet8[value]),ALLSELECTED(Sheet8))
VAR YEARS = CALCULATE(DISTINCTCOUNT(Sheet8[YEAR]),ALLSELECTED(Sheet8))
RETURN DIVIDE(SUM_VALUE,YEARS)

Create another measure as conditional formatting.

You can then use icon to represent the trend of each year relative to the total average.

test-icon.PNG

Here is the sample pbix.

 


Best Regards,
Liang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

amitchandak
Super User
Super User

Try like with date calendar

measure =
var _max = format(maxx('Date','Date'[Date]),"MMDD")
var _min = format(Minx('Date','Date'[Date]),"MMDD")

return
CALCULATE(SUM(Data[Amount]), FILTER('Date', format('Date'[Date],"MMDD") >=_min && format('Date'[Date],"MMDD") <=_max ))

 

To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :
https://radacad.com/creating-calendar-table-in-power-bi-using-dax-functions
https://www.archerpoint.com/blog/Posts/creating-date-table-power-bi
https://www.sqlbi.com/articles/creating-a-simple-date-table-in-dax/

Ashish_Mathur
Super User
Super User

Hi,

Share some data and show the expected result.


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

 

VAR __Max = MAX('Date'[Date])

VAR __Min = MIN('Date'[Date])

VAR __Table =

  UNION(

    FILTER(ALL('Table'),MONTH([Date]) > MONTH(__Min) && MONTH([Date]) < MONTH(__Max)),

    FILTER(ALL('Table'),MONTH([Date]) = MONTH(__Min) && DAY([Date]) >= DAY(__Min)),

    FILTER(ALL('Table'),MONTH([Date]) = MONTH(__Max) && DAY([Date]) <= DAY(__Max))

  )

RETURN

<some calculation across __Table>

 

 


@ 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
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.