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

trouble with date subtraction

I'm trying to look at a rolling 4 weeks, so I created a sum with filter of max[date] and max[date] - 28 for my filter range.  It wasn't working so I broke down the elements and i'm at the -28 date.  it doesn't seem to work.  I tried to do a DATE(year, month, day) and that didn't work, finding out just nomral max[date] - 28 breaks my output:

 

if I put in
!MaxDateMin28 = DAY(MAX(cwtime[Date_Start]))
I get an output of:
!MaxDate: 01/04/19
iMaxDateMin28: 4
 
if I put in 
!MaxDateMin28 = DAY(MAX(cwtime[Date_Start])) - 1
I get a unfilterd list of weeks, so for most of it:
!MaxDate: [blank]
iMaxDateMin28: -1
 
I tried without bothering with DAY and that resulted in date of 12/29/1899 12:00:00 AM
 
any help on how I can create a filter for 4 weeks range?
1 ACCEPTED SOLUTION

actually, thats worse.  when I use my date table then it breaks the filter and shows all dates in the matrix regardless if I try to subtract days.  When I use the date field in the table I'm working with it works fine as long as I don't subtract, adding the subtract breaks the filter and shows all dates with lots of empty fields.

Currently I have it giving the desired results with:

!MaxDateMin28 = IF(MAX(cwtime[Date_Start]) <> BLANK(), MAX(cwtime[Date_Start]) - 28)



View solution in original post

4 REPLIES 4
Ashish_Mathur
Super User
Super User

Hi,

Create a Calendar Table and build a relationship from the Date_Start column of the cwtime Table to the Date column of the Calendar Table.  To your visual, drag Date from the Calendar Table.  Write this measure

=CALCULATE(SUM(Data[Value]),DATESBETWEEN(Calendar[Date],MIN(Calendar[Date])-28,MIN(Calendar[Date])))

Hope this helps.


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

I have tried that, I do have a date table and orginally referenced that table in the query instead.

 

I would be willing to try again if you think it would matter, but since the date in this table is a date field, its should work.  Further, functions like DAY on that filed do return the proper result.

What it seems to be doing is killing the filter on my output table, hence showing all results for all days, even though the list should only be for a narrow date range.  Because of this it is apply the -1 to a blank field as that was filtered out.

Seems a bit odd, I'm able to work around it with an additional IF(BLANK) statement before I apply the -1, but I'm confused what that is necessary.

Please try again.


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

actually, thats worse.  when I use my date table then it breaks the filter and shows all dates in the matrix regardless if I try to subtract days.  When I use the date field in the table I'm working with it works fine as long as I don't subtract, adding the subtract breaks the filter and shows all dates with lots of empty fields.

Currently I have it giving the desired results with:

!MaxDateMin28 = IF(MAX(cwtime[Date_Start]) <> BLANK(), MAX(cwtime[Date_Start]) - 28)



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.