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

View all the Fabric Data Days sessions on demand. View schedule

Reply
Anonymous
Not applicable

Difference between two dynamic periords (Year or quarter based on filter)

Hello,

I've been trying to use dynamic time intelligence measures but I couldn’t get the right outputs…

I’d like to calculate the difference between two periods based on a filter (Yearly vs Quarterly). I have a filter that allows me to summary absolute values quarterly or yearly, but when I try to calculate the differences between the period and its previous, I can’t.

My data:

DatetimeLabelAmount
31/12/20181

100

31/12/20191200
30/09/20201300
31/12/20201400
31/03/20211500
31/12/20182

100

31/12/20192200
30/09/20202100
31/12/20202100
31/03/202120

 

My output should be something like this:

- If Yearly filter is activated:

label31/12/201831/12/201931/12/2020
1null+100%+100%
2null+100%-50%

 

- If Quarterly filter is activated, all available data, since december is Q4:

label31/12/201831/12/201930/09/202031/12/202031/03/2021
1nullnullnull+33%+25%
2nullnullnull0%-100%

 

My measure is (# are notes, not in real code):

 

 

YOY% = 
VAR thisYear =
    SUM ( table[amount] )
VAR lastYear =
    CALCULATE ( SUM ( table[amount] ), DATEADD( table[datetime].[Date],-1, YEAR))
VAR lastQuarter =
    CALCULATE ( SUM ( table[amount] ), DATEADD(table[datetime].[Date],-1, QUARTER))
RETURN
     IF(COUNTROWS ( VALUES ( table[filter] ) ) = 1, ###if filter activated###
        DIVIDE ( thisYear - lastYear, lastYear, BLANK() ),
        DIVIDE ( thisYear - lastQuarter, lastQuarter, BLANK() )
    )

 

 

 

Two problems:

- I am getting good results when filter is not activated (second output table), but headers show only "year" and not quarters.

- It is calculating 2021 differences (-100%) with yearly filter when I do not have any Q42021 data.

 

Thank you very much.

 

2 REPLIES 2
amitchandak
Super User
Super User

@Anonymous , I think these are year and qtr behind measure. that you should switch based on selection

 

for this qtr vs last qtr diff

 

examples

QTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESQTD(('Date'[Date])))
Last QTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESQTD(dateadd('Date'[Date],-1,QUARTER)))

 

year diff

 

YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD('Date'[Date],"12/31"))
Last YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(dateadd('Date'[Date],-1,Year),"12/31"))

 

//Only year vs Year, not a level below

This Year = CALCULATE(sum('order'[Qty]),filter(ALL('Date'),'Date'[Year]=max('Date'[Year])))
Last Year = CALCULATE(sum('order'[Qty]),filter(ALL('Date'),'Date'[Year]=max('Date'[Year])-1))

 

diff = [This Year]-[Last Year ]
diff % = divide([This Year]-[Last Year ],[Last Year ])

 

To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :radacad sqlbi My Video Series Appreciate your Kudos.

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

Of course it won't work. You have to get familiar with how time-intel in PBI works. Time-intel functions need a proper date table, which you don't have. To start you can read this: Time Intelligence in Power BI Desktop - SQLBI

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI 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.