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
Ramachandran
Helper III
Helper III

YTD for same period (current month) Previous Year

Hi,

Currently, I'm getting the sales amount based on Year wise. but I want to show line for YTD of same current month(Oct) Previous Year and similarly Last 2 year (2019) also. I want to report looks like is below

 

Ramachandran_0-1634759737199.png

 

for your reference, I attached .pbix file here Period.pbix - Google Drive

Someone review and give me suggestion how to get achieve on this.

 

regards,

Ram

 

 

 

1 ACCEPTED SOLUTION

Ah. This is a fairly different request than I was thinking.

 

Try this

SalesYTDMonths = 
VAR ThisYear = CALCULATE ( MAX ('Table'[Year] ), ALLSELECTED ('Calendar' ) )
VAR MonthsYTD = CALCULATETABLE ( VALUES ('Calendar'[Month] ), 'Calendar'[Year] = ThisYear )
RETURN
    CALCULATE ( SUM ('Table'[Sales Amt] ), 'Calendar'[Month] IN MonthsYTD )
SalesRemainderMonths = SUM ('Table'[Sales Amt] ) - [SalesYTDMonths]

AlexisOlson_0-1634827355912.png

View solution in original post

3 REPLIES 3
AlexisOlson
Super User
Super User

If you have your calendar table set up as a proper date dimension, then you can write

SalesYTD = CALCULATE ( SUM ('Table'[Sales Amt] ), DATESYTD ('Calendar'[Date] ) )
SalesYTD-1 = CALCULATE ( [SalesYTD], DATEADD ('Calendar'[Date], -1, YEAR ))
SalesYTD-2 = CALCULATE ( [SalesYTD], DATEADD ('Calendar'[Date], -2, YEAR ))

 

For your file, you'll need to create a relationship from 'Calendar' to a date column on 'Table'. I'd recommend defining a new calculated column 

Date = DATEVALUE ( 'Table'[Month] & " " & 'Table'[Year] )

Then set up the relationship like this:

AlexisOlson_0-1634763504342.png

 

Thanks for your update. After updating the code and I'm getting the report 

Ramachandran_0-1634792329233.png

But, I want to something different, Is it possible to show the report is like

Ramachandran_1-1634793381525.png

the report data based on my samples.

fyr, I have attached latest report is here Period_updated.pbix - Google Drive

 

regards,

Ram

Ah. This is a fairly different request than I was thinking.

 

Try this

SalesYTDMonths = 
VAR ThisYear = CALCULATE ( MAX ('Table'[Year] ), ALLSELECTED ('Calendar' ) )
VAR MonthsYTD = CALCULATETABLE ( VALUES ('Calendar'[Month] ), 'Calendar'[Year] = ThisYear )
RETURN
    CALCULATE ( SUM ('Table'[Sales Amt] ), 'Calendar'[Month] IN MonthsYTD )
SalesRemainderMonths = SUM ('Table'[Sales Amt] ) - [SalesYTDMonths]

AlexisOlson_0-1634827355912.png

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.