Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Srinivas3350
Helper II
Helper II

Need a urgent help in DAX

Hello, I am having some measure which is calculating current - previous year which is showing right now i need a another measure that need to calculate current year - previous previous year (ex: 2023-2021). I tried so many things to to acheive it but i cant can anyone help me this is measure i am using for current - previous year now i need 1 more current - previousprevious year(2023-2021)

 

PYLYYTD = CALCULATE([GBP],DATESBETWEEN(DIM_TIME[Full_Date],DATE(YEAR(TODAY())-1,1,1),EDATE(today(),-12)-1))
 

Srinivas3350_0-1697813915071.png

 

12 REPLIES 12
Dangar332
Super User
Super User

hi, @Srinivas3350 

use dateadd function which give you flexibility of choose  previous two year 
like dateadd(yourdatecolumn,-2,year)

Hi @Dangar332 , could you please provde me any example where should i add this function

@Srinivas3350 What is the code for the GBP measure?



Follow on LinkedIn
@ 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!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Hi @Greg_Deckler 
 it is just GBP column divided by 1000 

GBP = SUM('Table'[GBP_VALUE])/1000

@Srinivas3350 Maybe:

PYLYYTD = 
  VAR __MinDate = DATE(YEAR(TODAY())-1,1,1)
  VAR __MaxDate = EDATE(TODAY(),-12)-1
  VAR __Table = FILTER( 'Table', [Date] <= __MaxDate && [Date] >= __MinDate)
  VAR __Result = SUMX(__Table, [GBP]) / 1000
RETURN
  __Result


Follow on LinkedIn
@ 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!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

PYLYYTD = CALCULATE([GBP],DATESBETWEEN(DIM_TIME[Full_Date],DATE(YEAR(TODAY())-1,1,1),EDATE(today(),-12)-1))

 

in here you can use dateadd function instead of  DATESBETWEEN function

Hi @Dangar332 
this is the error showing
The last argument must be one of these keywords: DAY, MONTH, QUARTER, or YEAR.

hi, @Srinivas3350 

PYLYYTD = CALCULATE([GBP], dateadd('yourtablename'[datecolumnname],-2,year))

 


PYLYYTD = CALCULATE([GBP], dateadd('yourtablename'[datecolumnname],-2,year))

 

visit HERE to know more about time intelligence function

this is some how working but complete 2021 figure can we modify this to year to date

 

Srinivas3350_0-1697816471385.png

this is hsoing full 2021 value for the above formula u gave i need it for ytd 

hi, @Srinivas3350 

can we modify this to year to date?

means you want sum of date from two year back to today(1/1/2021 to 10/20/2023)
if yes then try below 

var a = today()

var b =date(year(today())-2,1,1)
var c = filter('yourdatetable','yourdatetable'[datecolumn]<=a && 'yourdatetable'[datecolumn]>=b )
return 
sumx(c,[gbp])/1000

 

or

 if you want data from today to previous two years(10/20/2021 to 10/20/2023)

try below 
var a = today()

var b  = edate(today()-24)
var c = filter('yourdatetable','yourdatetable'[datecolumn]<=a && 'yourdatetable'[datecolumn]>=b )
return 
sumx(c,[gbp])/1000

 

If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly. Appreciate your kudos

Greg_Deckler
Community Champion
Community Champion

@Srinivas3350 You may find this helpful - https://community.powerbi.com/t5/Community-Blog/To-bleep-With-Time-Intelligence/ba-p/1260000

Also, see if my Time Intelligence the Hard Way provides a different way of accomplishing what you are going for.

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

 

Also:



Follow on LinkedIn
@ 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!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
November Fabric Update Carousel

Fabric Monthly Update - November 2025

Check out the November 2025 Fabric update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Users online (25)