Forum Discussion
Calculate YTD using Short Month Name
Hello
I need to calculate the YTD value excluding the current month. I have the following information in a data table with a Month column. I added the Month_Number column using Switch. I now need to Divide the Sum of the EAC column by the Sum of the Revenue EAC column for the last one month given that we are in Feb. If we were in June, the sum would be all the past months excluding June. How do I do this?
Thank you for any suggestions.
Yoshi
thanks Ashish_Mathur danextian amitchandak stretcharm for all your help.
I was able to solve this using Ashish_Mathur solution.
I also found a similar solution here which also worked - https://community.powerbi.com/t5/Desktop/TotalYTD-to-Last-Month/m-p/692437
Correct Formula = VAR pre = CALCULATE ( MAX ( 'CalendarAuto'[Date] ), FILTER ( 'CalendarAuto', DATEDIFF ( 'CalendarAuto'[Date], TODAY (), MONTH ) = 1 ) ) RETURN CALCULATE( SUM(Sheet1[EAC]), FILTER( Sheet1, YEAR(Sheet1[Custom Date]) = YEAR(pre) && Sheet1[Custom Date] <= pre ) )The idea of using a separate Calendar table is a good one and one that I will use in the future I'm sure. Thanks danextian for the tip.
Thanks again.
Yoshi
13 Replies
- stretcharm
Memorable Member
I would use PowerQuery/M to create a date field from the Month.
I do that using the Add column from example in this video
https://www.youtube.com/watch?v=t1WLdABqZeQ
Once you have a date you can do YTD calcs easily.
Curbal has a video explaining YTD here.
- amitchandak
Super User
In case you have the date you can use time intelligence using date table
If you have a month then you convert into the date
date = date(table[year],date[month],1)
Then try like
YTD Sales month back = CALCULATE([Sum Sales],DATESYTD(ENDOFMONTH(DATEADD('Date'[Date Filer],-1,MONTH))))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/Appreciate your Kudos. In case, this is the solution you are looking for, mark it as the Solution.
In case it does not help, please provide additional information and mark me with @
Thanks. My Recent Blogs -Decoding Direct Query - Time Intelligence, Winner Coloring on MAP, HR Analytics, Power BI Working with Non-Standard TimeAnd Comparing Data Across Date Ranges
Connect on Linkedin- amitchandak
Super User
You can get with the month number, but that will require all to be used. So move month and year to another table and join with this.
Till last month =
var _max = maxx(Month,Month[Month No]) -1
Var _maxYear = maxx(Month, Month[year])
YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),fiter(all(Month),Month[Month]= _max && Month[Year]=_maxYear ))
- Yoshimitsu411
Resolver I
Hello All
Thanks for the suggestions.
I have added two columns to my data table based on the above suggestions.
Custom Month Number = SWITCH('Zinfra ADPR Forecast'[Month], "JAN", 1, "FEB", 2, "MAR", 3, "APR", 4, "MAY", 5, "JUN", 6, "JUL", 7, "AUG", 8, "SEP", 9, "OCT", 10, "NOV", 11, "DEC", 12) Custom Date Created to Calculate YTD = DATE(2020, 'Table'[Custom Month Number], 1)I then get this in my data table.
Now I can calculate the TotalYTD using the formula below but it doesn't give me the correct result.
YTD = TOTALYTD(SUM('Table'[EAC]), 'Table'[Custom Date Created to Calculate YTD].[Date])I want the value for all past months excluding the current month.
Thanks again.