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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
Sidhu
Frequent Visitor

Getting Same Period Last Year without date table

I have table with moving dates for months , below is the format. Now I need to calculate the time intelligence functions like Same Period Last Year, if the user selects 2022 P1,2022 P2, I need to display the values for same period last year like 2021 P1, 2021 P2. what is the easy way to do this?

Sidhu_0-1669673441527.png

 

2 REPLIES 2
ghaines
Resolver I
Resolver I

I really would recommend a date table, you could construct one from scratch and then add the periods required and it opens up many other options.  That also gives you the flexibility you get when your date ranges are non contiguous.

 

However...

 

You could use something like this:

 

MeasureName = 
VAR PeriodStart = EDATE(SELECTEDVALUE('Date Table'[Start Date]), -12)
VAR PeriodEnd = EDATE(SELECTEDVALUE('Date Table'[End Date]), -12)

RETURN
SUMX(
    VALUES('Date Table'[Month)),
    CALCULATE(SUM('Fact Table'[Value]),
        FILTER(VALUES('Fact Table'[Transaction Date]),
            'Fact Table'[Transaction Date] >= PeriodStart &&
            'Fact Table'[Transaction Date] <= PeriodEnd
        )
    )
)

 

I have not tested this code because I am at work and just throwing something together while data loaded, it could have some overlooked context issues so please test.  For averages you're better off making two measures like this and then dividing e.g. AvgPrice = DIVIDE([Total Price], [Total Units])

djurecicK2
Super User
Super User

@Sidhu ,

 The easiest way to do this is with a date table- here is some additional information:

https://kteam.ch/why-almost-every-power-bi-report-needs-a-date-table/

 

https://learn.microsoft.com/en-us/dax/sameperiodlastyear-function-dax

 

 

Please accept as solution if this has answered the question- thanks!

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

Find out what's new and trending in the Fabric Community.

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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