cancel
Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

Reply
avulasandeep
Helper III
Helper III

Difference of THIS YEAR YTD and LAST YEAR YTD

Hi  Everyone ,  

 

here i have one question that i need subtraction of YTD of one year with YTD of another Year. 

 

As i mentioned requirement in below screenshot.

req1.jpgreq 2.jpg 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Please Tell me is that possible  the Difference of the YTD of  this  year - YTD of last year.

 

Thanks 

Sandeep

 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Assuming you have a Calendar Table (if you don't, use the date field on current table), create YTD measure (change name of tables and columns):

 

VALUE YTD = 
IF(
	ISFILTERED('Calendar'[Date]);
	ERROR("Time intelligence quick measures can only be grouped or filtered by the Power BI-provided date hierarchy or primary date column.");
	TOTALYTD(SUM('TABLE'[VALUE]; 'Calendar'[Date].[Date])
)

Create Previous YTD measure:

 

VALUE PYTD = 
VAR pytddate1 = DATEADD(DATEADD(DATEADD(ENDOFYEAR ( 'Calendar'[Date] );-1;YEAR);1;DAY);-1;YEAR)
VAR pytddate2 = DATEADD ( ENDOFMONTH ( 'Calendar'[Date] ); -1; YEAR )
RETURN
CALCULATE (
    SUM['TABLE'[VALUE];
    FILTER (
        ALL ( 'Calendar'[Date] );
        'Calendar'[Date]
            >= pytddate1
            && 'Calendar'[Date] <= pytddate2
    )
)

Then calculate the difference:

 

VALUE PYTDG = [VALUE YTD] - [VALUE PYTD]

View solution in original post

4 REPLIES 4
v-huizhn-msft
Microsoft
Microsoft

Hi @avulasandeep,

You need a calendar table as @Anonymous said, and please mark the right reply as answer if you have resolved your issue.

Thanks,
Angelia

Anonymous
Not applicable

Assuming you have a Calendar Table (if you don't, use the date field on current table), create YTD measure (change name of tables and columns):

 

VALUE YTD = 
IF(
	ISFILTERED('Calendar'[Date]);
	ERROR("Time intelligence quick measures can only be grouped or filtered by the Power BI-provided date hierarchy or primary date column.");
	TOTALYTD(SUM('TABLE'[VALUE]; 'Calendar'[Date].[Date])
)

Create Previous YTD measure:

 

VALUE PYTD = 
VAR pytddate1 = DATEADD(DATEADD(DATEADD(ENDOFYEAR ( 'Calendar'[Date] );-1;YEAR);1;DAY);-1;YEAR)
VAR pytddate2 = DATEADD ( ENDOFMONTH ( 'Calendar'[Date] ); -1; YEAR )
RETURN
CALCULATE (
    SUM['TABLE'[VALUE];
    FILTER (
        ALL ( 'Calendar'[Date] );
        'Calendar'[Date]
            >= pytddate1
            && 'Calendar'[Date] <= pytddate2
    )
)

Then calculate the difference:

 

VALUE PYTDG = [VALUE YTD] - [VALUE PYTD]
Greg_Deckler
Super User
Super User

So, if you have a separate Date table, then you should be able to use time intelligence functions and the general format of those would be:

 

Sales YTD = TOTALYTD(Sum('Sales'[Revenue]),'Date'[Date])

Sales LY YTD = CALCULATE ([Sales YTD], SAMEPERIODLASTYEAR ('Date'[Date]))

Sales Var = [Sales YTD]-[Sales LY YTD]

If you do not have a separate date table either create one or check out my Time Intelligence The Hard Way Quick Measure:

 

https://community.powerbi.com/t5/Quick-Measures-Gallery/Time-Intelligence-quot-The-Hard-Way-quot-TIT...


@ 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!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

Well... I'm glad I also replied because I learned something... hehehe

Helpful resources

Announcements
PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

Check out the November 2023 Power BI update to learn about new features.

Community News

Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors