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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
globalwarme
Frequent Visitor

dynamic time shifting

I am working with a group of public traded companies all with different year ends.  For example Apple's last year-end was September 30, 2020 while Target's was Jan 31, 2021.  I am trying to build a measure that will dynamically allow me to pull in a series of year ends for both companies.  The last year end I can handle with the LASTYEAR function, but I am having trouble dynamically pulling in dates for previous years.  PREVIOUSYEAR and DATEADD functions don't seem to work because they key off of my dateDim table, which can't tell between different year ends.  What I need to be able to do is move back one and two years from the LASTYEAR value, but can't seem to find a way to do this.  For example, my LASTYEAR value for Apple is September 30, 2020 and for Target is Jan 31, 2021 as expected.  But my previous year value for Apple is still September 20, 2020, which is not correct, while the previous year value for Target is correct.  Not sure how to handle this.  Any ideas how to handle this dynamically.  Many thanks

2 REPLIES 2
Anonymous
Not applicable

@globalwarme 

 

I can't say your description is clear. Please give us a concrete example as close to the reality as possible. Best, explaining this with DAX and visuals.

OK here is the Table (working in power pivot) with the date field representing the last reported fiscal year end for the companies.  Notice they are all different.

globalwarme_0-1617844474824.png

I am trying to create a dynamic reporting table that pulls in the right reporting dates for each company which will include last reported date and previous year, previous year + 1, previous year +2, etc.

 

I can't just selct for the year, because as you will notice the last reported years don't match - for Walmart and Target the last reported year is 2021, but for Costco it is 2020.  This also complicates things when I try to use the PREVIOUSYEAR or DATEADD - 1 function.  The LASTDATE function produces the correct value for all of them, but when I try to shift back one year, it doesn't work (for Costco), because I have to key off of the DateDim table.

globalwarme_2-1617845713533.png

 

Here is the DAX

 

lastDate = LASTDATE([incomeStatement[date])

 

and then for the previous year I used:

 

PY = CALCULATE([lastDate], DATEADD(dateDim[date], -1, YEAR))

 

I hope this clarifies my problem.

 

Thanks again,

P

Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

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

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.

Top Solution Authors