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
gsmith_eqd
Frequent Visitor

Sum Last Full Month MTD and YTD based on current date

Hello,

 

I'm trying to build a report that has cards showing A) last months total sales, B) last month previous year total sales, C) YTD sales up to present date, and D) previous YTD sales up to present date. So for example, if the date was March 14, 2023, A) would display total sales for February 2023, B) would display sales for February 2022, C) would display YTD sales up to March 14, 2023, and D) would display previous YTD Sales up to March 14, 2022.

 

So far, these are some of the measures I have created on the InvoiceLine table:

 

Total Invoicing = SUM(InvoiceLine[InvoiceLineAmount])

InvoiceYTD = TOTALYTD([Total Invoicing], 'calendar'[Date].[Date])

InvoicePYYTD = TOTALYTD([Total Invoicing], SAMEPERIODLASTYEAR('calendar'[Date].[Date]))

InvoiceMTD = TOTALMTD([Total Invoicing], 'calendar'[Date].[Date])

InvoicePYMTD = TOTALMTD([Total Invoicing], SAMEPERIODLASTYEAR('calendar'[Date].[Date]))

 

I have a calendar table linked to InvoiceLine with the columns: Date, Day, Month, Monthnum, QTR, Weeknum, and Year.

 

 

PBI Capture 1.27(1).PNGPBI Capture 1.27(2).PNG

 

In these samples I created, the data was updated on 1/17/2023, so I've selected the periods on the tables that I would like to display so the cards show the YTD invoicing up to 1/17 and the MTD invoicing for December 2022 and 2021. However, the behavior I'm hoping to achieve is that I can have these cards all on one page without the need to focus on the period in a table as it is the hope that users of this report will be able to display this information at a glance without having to filter the information either with the focus tool or filters.

 

I was able to create a measure for C) above that reads like this:

 

ThisYearToDayInvoicing = TOTALYTD([Total Invoicing], 'calendar'[Date].[Date], 'calendar'[Date] <= TODAY() && 'calendar'[Year] = YEAR(today()))

 

but when I when I try to create the same measure for last year, it comes up blank:

 

LastYearToDayInvoicing = TOTALYTD([Total Invoicing], SAMEPERIODLASTYEAR('calendar'[Date].[Date]), 'calendar'[Date] <= TODAY() && 'calendar'[Year] = YEAR(today()))

 

This is the formula I tried for the MTD measure but did not return a value:

 

LastMTD = TOTALMTD([Total Invoicing], 'calendar'[Date].[Date], ('calendar'[Monthnum] = 'calendar'[Monthnum] - 1 && 'calendar'[Monthnum] <> 1) || 'calendar'[Monthnum] = 12)

 

Can I accomplish this with DAX formulas or are there other considerations I need to make about which tools will be needed to accomplish this?

 

Thanks,

Gavin

 

 

1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

@gsmith_eqd You may find this helpful - https://community.powerbi.com/t5/Community-Blog/To-bleep-With-Time-Intelligence/ba-p/1260000

Also, see if my Time Intelligence the Hard Way provides a different way of accomplishing what you are going for.

https://community.powerbi.com/t5/Quick-Measures-Gallery/Time-Intelligence-quot-The-Hard-Way-quot-TIT...


@ 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...

View solution in original post

1 REPLY 1
Greg_Deckler
Super User
Super User

@gsmith_eqd You may find this helpful - https://community.powerbi.com/t5/Community-Blog/To-bleep-With-Time-Intelligence/ba-p/1260000

Also, see if my Time Intelligence the Hard Way provides a different way of accomplishing what you are going for.

https://community.powerbi.com/t5/Quick-Measures-Gallery/Time-Intelligence-quot-The-Hard-Way-quot-TIT...


@ 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...

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.

Top Solution Authors