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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Betobri
Frequent Visitor

Calculate YTD data while having monthly and weekly filters

Hello everyone,

 

I'm trying to make a scorecard report on Power BI, which gives me the weekly, MTD and YTD information about plant production, but i'm having trouble getting the correct YTD information.

I have a separate calendar table which connects to 5 different data sources by a Date Key column: 

Date key = 'Plant Scorecard - Conformance'[Year]&"-"&'Plant Scorecard - Conformance'[Month]&"-"&'Plant Scorecard - Conformance'[Week]
I don't have a date column on these datasource, that's why i made the Date Key.
This is the connections i have are made this way:
ConnectionsConnections
My data table looks like this:
TableTable
What i need to do is to show the Last Week, Month-To-Date and Year-To-Date information, and being able to filter it by Month and week and the data to be dynamic.
 
My main problem is that everytime i try to do the YTD formula, it keeps giving me the Last Week information, instead of the YTD, like the data was being filtered and it's not showing me the accumulative data since the start of the year.
 
The DAX formula i used to calculate the YTD information was this:
CALCULATE([Eff %],DATESYTD('Production Analysis'[Week End].[Date]))
 
Do i need to change my connections or do something different? Or do i need to use another formula in order to make it work? The MTD measure is not giving any problems, so i don't know how can i make it work for the YTD.
 
I'd really appreciate any help you guys could give me, i'm fairly new to Power BI so in case wasn't clear enough i'll try to explain it in a reply.
 
Thanks in advance.
 
 
 
5 REPLIES 5
amitchandak
Super User
Super User

Seem like you have a date calendar. And I am assuming you have Month, year, week defined there.

For week use rank and find last week. Refer this file

https://www.dropbox.com/s/d9898a48e76wmvl/sales_analytics_weekWise.pbix?dl=0

 

For YTD and MTD use total* or dates* time intelligence functions

examples

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 MTD (complete) Sales =  CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(ENDOFMONTH(dateadd('Date'[Date],-1,MONTH))))
last year MTD (complete) Sales =  CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(ENDOFMONTH(dateadd('Date'[Date],-12,MONTH))))
last year MTD Sales =  CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(dateadd('Date'[Date],-12,MONTH)))


last QTR same Month (complete) Sales =  CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(ENDOFMONTH(dateadd('Date'[Date],-1,Qtr))))


MTD (Year End) Sales =  CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(ENDOFYEAR('Date'[Date])))
MTD (Last Year End) Sales =  CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(ENDOFYEAR(dateadd('Date'[Date],-12,MONTH),"8/31")))

YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(('Date'[Date]),"12/31"))
This Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD((ENDOFYEAR('Date'[Date])),"12/31"))

Last YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(dateadd('Date'[Date],-1,Year),"12/31"))
Last YTD complete Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(ENDOFYEAR(dateadd('Date'[Date],-1,Year)),"12/31"))
Last to last YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(dateadd('Date'[Date],-2,Year),"12/31"))

Year behind Sales = CALCULATE(SUM(Sales[Sales Amount]),dateadd('Date'[Date],-1,Year))

 

With Week and MTD i'm not having any problems, and i'm using the exact formula for YTD as you've mentioned.

My Date table does have a Week, Month and Year columns, but they're numbers.

DatesDates

I'm still having problems even with your formula.

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


Follow on LinkedIn
@ 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...

How you have joined these two tables. Date table should have all dates And if you have data at week level you should be joined Week end or start date.

In dateytd you have to pass the calendar date which is marked at date or is the join date

 

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/

@Betobri ,Does the above replies helps. if you need more help make me @

Appreciate your Kudos.

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Power BI Monthly Update - May 2024

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

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.