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

How to obtain YTD value for one month prior BUT if January, then just last December of prior year?

I am wanting to calculate YTD for a parrallelperiod, in this case prior month.  The equation is straight forward but where I run into trouble is when the current period is January, then it I get YTD for the entirely of the prior year (since the one month prior to January is Decembe of the prior year).

 

So what I want is if the month is January, then for the measure to return the value for December of the prior year.

 

This is what I currently have.

NewAccounts YTD LastMonth =
CALCULATE(
SUM( Production[NewAccounts] ),
DATESYTD( PARALLELPERIOD( 'CalendarAuto'[Date], -1, MONTH ) ),
)
 
I've tried using an IF() statement but PowerBi won't recognize a date table/filed in an IF() statement
1 ACCEPTED SOLUTION
VocationSmart
Frequent Visitor

I solved this by limiting the minimum date witin the date table:

 

CALCULATE(
   SUM( QryProduction_3yrs[NewAccounts] ),
   DATESYTD( PARALLELPERIOD( 'CalendarAuto'[Date], -1, MONTH ) ),
   FILTER(
      ALL('CalendarAuto'[Date]),
      'CalendarAuto'[Date] <= EOMONTH( TODAY(), -1) -- date maximum
         && 'CalendarAuto'[Date] >= DATE( YEAR( TODAY() ) -1, 12, 1) -- date minimum 
   )
)

View solution in original post

1 REPLY 1
VocationSmart
Frequent Visitor

I solved this by limiting the minimum date witin the date table:

 

CALCULATE(
   SUM( QryProduction_3yrs[NewAccounts] ),
   DATESYTD( PARALLELPERIOD( 'CalendarAuto'[Date], -1, MONTH ) ),
   FILTER(
      ALL('CalendarAuto'[Date]),
      'CalendarAuto'[Date] <= EOMONTH( TODAY(), -1) -- date maximum
         && 'CalendarAuto'[Date] >= DATE( YEAR( TODAY() ) -1, 12, 1) -- date minimum 
   )
)

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.