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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
kcantor
Community Champion
Community Champion

Smart DAX Last Year To Date

 

Question for those DAX Gurus amoung us.

I have the measures in place for YTD Sales  and Last YTD Sales. These return values that are spot on but I want more. What I would like to create is a measuer for Last YTD that cuts off the calculations based upon yesterday's date so that I can plug it in to my reports and not have to worry about updating filters to cut off the data for a particular user who wants up-to-date sales figures. As of now, it pulls in last year YTD sales through the end of my filter. So, if I am filtering by the month it pulls in through the end of the month where I only want last years sales through the current date.

Is it possible to build this to pull the last invoiced date found in the sales information and back that up a year so that I don't have to add granular filters?

 

My Sales table is tied to my date table by both Order Date and by Posting Date. Posting Date uses USERELATIONSHIP. 

 

For YTD Invoiced Sales I am using: =TOTALYTD([Total Sales by Posting Date], DimDate[DateKey])

 

For Last YTD Sales I am using : =CALCULATE([Invoiced Sales YTD], DATEADD(DimDate[DateKey], -1, year))





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




6 REPLIES 6
vlahoz
Frequent Visitor

I calculate columns for today, previous month, year, day, etc., in the date's table. Put this columns in filters and your reports evolves in time.

Greg_Deckler
Super User
Super User

Can you do something like:

 

=CALCULATE([Invoiced Sales YTD], DATEADD(DimDate[DateKey], -1, year) && DimDate[DateKey] < TODAY())

Or perhaps

=CALCULATE([Invoiced Sales YTD], DATEADD(DimDate[DateKey], -1, year), DimDate[DateKey] < TODAY())

@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

@Greg_Deckler I tried to use your formula it works well when you have CARD visuals, but when I have table chart with states having 5 years data. it gives me all data and I am supposed to get only last year current month data.

 

How to achieve this.

 

Thanks,

Thimma

Can you post some sample data so that I can play with the solution?


@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

Thanks for the reply, but I am not able to attach any file here.

 

Thanks,
Thimma

Anonymous
Not applicable

Current vs pre com.pngPls refer the screenshot, but my output should be as below

 

 

Current vs Pre outpuot.png

 

 

 

 

 

 

and even I don't need 2015 and 2014 as I am comparing current vs previous years

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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