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

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

Reply
Anonymous
Not applicable

Time Intelligence Functions

Hi Guru's,

 Hope you are doing good. I need your help in figuring out the formula for couple of new metrics.  I am new to Power BI and this is my 3rd day playing with the tool. I have created "Current Year YTD Sales" and "Prior Year YTD Sales" by looking at few blogs and discussion forum.  Now, the other requirement is to create "Prior Year Next Month Sales" which is Aug 2019 and "Prior Year  Next 3 Month Sales" which is a total sales of Aug 2019, Sep 2019 and Oct 2019. Could you please help me.

Thanks, Sandeep

9 REPLIES 9
v-alq-msft
Community Support
Community Support

Hi, @Anonymous 

 

Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.

 

Table:

d1.png

 

Calendar(a calculated table):

Calendar = CALENDAR(DATE(2018,1,1),DATE(2020,12,31))

 

 There is no relationship between two tables. You may create calculated columns and meausres as below.

Calculated column:
CalendarYearMonth = YEAR('Calendar'[Date])*100+MONTH('Calendar'[Date])

YearMonth = YEAR('Table'[Transaction Date])*100+MONTH('Table'[Transaction Date])

Measure:
Current year Sales = 
var tab = 
SUMMARIZE(
    'Table',
    'Table'[Customer],
    "Current Month Sales",
    CALCULATE(
        SUM('Table'[Amount]),
        FILTER(
            ALL('Table'),
            'Table'[Customer]=EARLIER('Table'[Customer])&&
            YEAR('Table'[Transaction Date])=YEAR(TODAY())&&
            MONTH('Table'[Transaction Date])=MONTH(TODAY())
        )
    )
)
return
SUMX(
    tab,
    [Current Month Sales]
)

Prior Year Next 1 Month sales = 
var tab = 
SUMMARIZE(
    'Table',
    'Table'[Customer],
    "Prior Year Next 1 month sales",
    var _customer = [Customer]
    return
    CALCULATE(
        SUM('Table'[Amount]),
        FILTER(
            ALL('Table'),
            'Table'[Customer] = _customer&&
            'Table'[YearMonth] =
            CALCULATE(
                MIN('Calendar'[CalendarYearMonth]),
                FILTER(
                    ALL('Calendar'),
                    'Calendar'[CalendarYearMonth]>(YEAR(TODAY())-1)*100+MONTH(TODAY())
                )
            )
        )
    )
)
return
SUMX(
    tab,
    [Prior Year Next 1 month sales]
)

Prior Year Next 3 Month sales = 
var tab = 
SUMMARIZE(
    'Table',
    'Table'[Customer],
    "Prior Year Next 3 month sales",
    var _customer = [Customer]
    return
    CALCULATE(
        SUM('Table'[Amount]),
        FILTER(
            ALL('Table'),
            'Table'[Customer] = _customer&&
            'Table'[YearMonth] in
            TOPN(
                3,
                FILTER(
                    ALL('Calendar'[CalendarYearMonth]),
                    'Calendar'[CalendarYearMonth]>(YEAR(TODAY())-1)*100+MONTH(TODAY())
                ),
                [CalendarYearMonth],ASC
            )
        )
    )
)
return
SUMX(
    tab,
    [Prior Year Next 3 month sales]
)

 

Result:

d2.png

 

Best Regards

Allan

 

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

Anonymous
Not applicable

@v-alq-msft . Thanks for your message. 

 

Not able to open the file that you sent. Please see the attached screenshot. I have installed multiple times but no luck.

 

Capture.PNG

 

Thanks,

Sandeep

Hi, @Anonymous 

 

I attached the pbix file with the version of 2020 July. Today is 8/4/2020. Here is the result.

g1.png

 

Best Regards

Allan

 

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

Anonymous
Not applicable

@v-alq-msft 

 

Thanks for your help on this. 

But the report is still showing null values in my PBI report. 

Our data looks like below.  

Capture.PNG

Your help and support is greatly appreciated. 

 

Thanks,

Sandeep

Hi, @Anonymous 

 

Power BI Desktop is updated and released on a monthly basis, incorporating customer feedback and new features. Only the most recent version of Power BI Desktop is supported; customers who contact support for Power BI Desktop will be asked to upgrade to the most recent version. You can get the most recent version of Power BI Desktop from the Windows Store.

 

 

Best Regards

Allan

amitchandak
Super User
Super User

@Anonymous , with time intelligence and date table

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"))

 

MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD('Date'[Date]))
last MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(dateadd('Date'[Date],-1,MONTH)))

last year MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(dateadd('Date'[Date],-12,MONTH)))

 

last year MTD Sales next month = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(dateadd('Date'[Date],-11,MONTH)))

last year MTD Sales next to next month = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(dateadd('Date'[Date],-10,MONTH)))

 

same way you can use rolling

Rolling 3 till last 12 month = CALCULATE(sum(Sales[Sales Amount]),DATESINPERIOD('Date'[Date],ENDOFMONTH(dateadd(Sales[Sales Date],-9,month)),-3,MONTH))

Rolling 3 till last month = CALCULATE(sum(Sales[Sales Amount]),DATESINPERIOD('Date'[Date],ENDOFMONTH(dateadd(Sales[Sales Date],-1,month)),-3,MONTH))
Rolling 3 till last 2 month = CALCULATE(sum(Sales[Sales Amount]),DATESINPERIOD('Date'[Date],ENDOFMONTH(dateadd(Sales[Sales Date],-2,month)),-3,MONTH))
Rolling 3 till last 1 month = CALCULATE(sum(Sales[Sales Amount]),DATESINPERIOD('Date'[Date],ENDOFMONTH(dateadd(Sales[Sales Date],-1,month)),-3,MONTH))
Rolling 3 till last 3 month = CALCULATE(sum(Sales[Sales Amount]),DATESINPERIOD('Date'[Date],ENDOFMONTH(dateadd(Sales[Sales Date],-3,month)),-3,MONTH))

 

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 :
https://radacad.com/creating-calendar-table-in-power-bi-using-dax-functions
https://www.archerpoint.com/blog/Posts/creating-date-table-power-bi
https://www.sqlbi.com/articles/creating-a-simple-date-table-in-dax/

See if my webinar on Time Intelligence can help: https://community.powerbi.com/t5/Webinars-and-Video-Gallery/PowerBI-Time-Intelligence-Calendar-WTD-YTD-LYTD-Week-Over-Week/m-p/1051626#M184

 

 

Power BI — YTD Questions — Time Intelligence 1–5
https://medium.com/@amitchandak.1978/power-bi-ytd-questions-time-intelligence-1-5-e3174b39f38a
Power BI — QTD Questions — Time Intelligence 2–5
https://medium.com/@amitchandak.1978/power-bi-qtd-questions-time-intelligence-2-5-d842063da839
Power BI — MTD Questions — Time Intelligence 3–5
https://medium.com/@amitchandak.1978/power-bi-mtd-questions-time-intelligence-3-5-64b0b4a4090e


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
Pragati11
Super User
Super User

HI @Anonymous ,

 

Can you share some sample data please?

https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

 

Thanks,

Pragati

 

Best Regards,

Pragati Jain


MVP logo


LinkedIn | Twitter | Blog YouTube 

Did I answer your question? Mark my post as a solution! This will help others on the forum!

Appreciate your Kudos!!

Proud to be a Super User!!

Anonymous
Not applicable

Hi Pragathi, 

 

Thanks for your reply. 

our issue is similar to the below post.

I have followed this post https://community.powerbi.com/t5/Desktop/Current-Month-Previous-Month-and-Before-Previous-Month/td-p... and ended up creating the Measures but column is showing blank data. 

 

 

 

Thanks,

Sandeep

 

Anonymous
Not applicable

Capture.PNG

@Pragati11 ...Please see the attached correct picture 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

Vote for your favorite vizzies from the Power BI World Championship submissions!

Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 Power BI update to learn about new features.

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.