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
Raulx_7
Helper I
Helper I

Last year from max date

Hi, I was doing some calculations, and in this one I use a filter to select the max date :

 

date = MAX(Date[Dates]), 

 

Now I need te value from the same date but in the last year, I have tried with 

date =  SAMEPERIODLASTYEAR (MAX(Date[dates]))

But it gives me an error with dates

 

Is there a way to solve this or I need to develop another solution

1 ACCEPTED SOLUTION
jbirco
Resolver I
Resolver I

you can try 'lydate = MAX(Date[Dates])-365' or you can try the DATEADD function

View solution in original post

3 REPLIES 3
Ryks
Frequent Visitor

I have the same problem and cannot get it to work.

Sameperiodlast year does not work.  OpenCurrentYTD is correct

 

OpenCurrentYTD =

Var Segmentvar = AllSELECTED(WorkersComp[Segment])

Var Divisionvar = AllSELECTED(WorkersComp[Sub-Segment])

Return

CALCULATE(Count(WorkersComp[Solvinjury ID]),WorkersComp[Segment] in Segmentvar,WorkersComp[Sub-Segment]in Divisionvar,

Filter(ALL(WorkersComp),( WorkersComp[InclusiveStatus]="Yes" && WorkersComp[DateSubmittedME] <= max('Calendar'[Date]) && WorkersComp[DateSubmittedME] <> Blank() && (('WorkersComp'[ClosedME] = Blank()) || WorkersComp[ClosedME] > max('Calendar'[Date]) ))))

 

Tried

PrevPeriod =

Var Segmentvar = AllSELECTED(WorkersComp[Segment])

Var Divisionvar = AllSELECTED(WorkersComp[Sub-Segment])

Var PrevPMax = EOMONTH(DATE(YEAR(TODAY()),MONTH(TODAY())-1,DAY(TODAY())),-12)

Return

CALCULATE(Count(WorkersComp[Solvinjury ID]),WorkersComp[Segment] in Segmentvar,WorkersComp[Sub-Segment]in Divisionvar,

Filter(ALL(WorkersComp),(WorkersComp[InclusiveStatus]="Yes" && WorkersComp[DateSubmittedME] <=PrevPMax && WorkersComp[DateSubmittedME] <> Blank() && (('WorkersComp'[ClosedME] = Blank()) || WorkersComp[ClosedME] >PrevPMax))))

 

And Tried

KeepFilters =

Var Segmentvar = AllSELECTED(WorkersComp[Segment])

Var Divisionvar = AllSELECTED(WorkersComp[Sub-Segment])

Var PrevPMax = EOMONTH(DATE(YEAR(TODAY()),MONTH(TODAY())-1,DAY(TODAY())),-12)

Return

CALCULATE(Count(WorkersComp[Solvinjury ID]),WorkersComp[Segment] in Segmentvar,WorkersComp[Sub-Segment]in Divisionvar,

Keepfilters(WorkersComp),(WorkersComp[InclusiveStatus]="Yes" && WorkersComp[DateSubmittedME] <=PrevPMax && WorkersComp[DateSubmittedME] <> Blank() && (('WorkersComp'[ClosedME] = Blank()) || WorkersComp[ClosedME] >PrevPMax)))

 

Results:

Ryks_0-1642839380455.png

 

Any ideas?

@MattAllington 

jbirco
Resolver I
Resolver I

you can try 'lydate = MAX(Date[Dates])-365' or you can try the DATEADD function

This is not valid syntax - you seem to be mixing inbuilt time intelligence with custom time intelligence. It seems you have a calendar table. The date from the calendar table needs to be in your visual. Then you could write this

 

=calculate([measure],sameperiodlastyear(date[date]))

 

read my article here https://exceleratorbi.com.au/dax-time-intelligence-beginners/

 

 



* Matt is an 8 times Microsoft MVP (Power BI) and author of the Power BI Book Supercharge Power BI.

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.