cancel
Showing results for
Did you mean:
Highlighted
Helper I

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

2 ACCEPTED SOLUTIONS

Accepted Solutions
Super User IV

## Re: pastRe: Calculate YTD using Short Month Name

Hi,

Hope this helps.

Regards,
Ashish Mathur
http://www.ashishmathur.com
Helper I

## Re: pastRe: Calculate YTD using Short Month Name

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 13
Memorable Member

## Re: Calculate YTD using Short Month Name

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

Once you have a date you can do YTD calcs easily.

Curbal has a video explaining YTD here.

Super User IV

## Re: Calculate YTD using Short Month Name

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://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

In case it does not help, please provide additional information and mark me with @
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
Proud to be a Super User! Linkedin

Super User IV

## Re: Calculate YTD using Short Month Name

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

In case it does not help, please provide additional information and mark me with @
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
Proud to be a Super User! Linkedin

Helper I

## pastRe: Calculate YTD using Short Month Name

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.

Super User IV

## Re: pastRe: Calculate YTD using Short Month Name

Use date dimension, As suggested in my last post and move month a back

``YTD = TOTALYTD(SUM('Table'[EAC]), dateadd(Date[Date],-1,Month))``

In case it does not help, please provide additional information and mark me with @
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
Proud to be a Super User! Linkedin

Super User I

## Re: pastRe: Calculate YTD using Short Month Name

Try this:

``````YTD Last Month =
CALCULATE (
[Measure],
//YTD before the earliest date in the currently selected month
FILTER (
DATESYTD ( Table[Date] ),
Table[Date] < MIN ( Table[Date] )
)
)
``````

Proud to be a Super User!

"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Helper I

## Re: pastRe: Calculate YTD using Short Month Name

The formula makes sense unfortunately it is giving me the wrong value.

Here is some sample data.

 Asset Partner Project ID Project Name JAN EAC FEB EAC MAR EAC APR EAC MAY EAC JUN EAC JUL EAC AUG EAC SEP EAC OCT EAC NOV EAC DEC EAC Contoso CON-TOSO-001 Lorem ipsum dolor sit amet 1 2 3 Contoso CON-TOSO-002 consectetur adipiscing elit. Donec rhoncus 2 3 4 Contoso CON-TOSO-003 arius diam consequat a. Maecenas eget 3 4 5 Contoso CON-TOSO-004 attis ex vestibulum in. Nulla ipsum velit 4 5 6 Contoso CON-TOSO-005 t tellus eget facilisis. Fusce posuere maximus leo 5 6 7 Contoso CON-TOSO-006 sapien sodales purus, at ornare odio 6 7 8 Contoso CON-TOSO-007 am laoreet pellentesque condimentum. Cras ac pellentesque odio 7 8 9 Contoso CON-TOSO-008 auris sapien sodales purus, at ornare 8 9 10 Contoso CON-TOSO-009 olutpat ac dignissim eget, dictum vitae magna. Duis et metus 9 10 11 Contoso CON-TOSO-010 placerat tellus eget facilisis 10 11 12

When I use your formula below, I get 120 which is the sum of JAN EAC and FEB EAC. What I want is 55 which is the sum of only JAN EAC because we are in the month of Feb. If we were in March then I would want to see 120 and so on.

``Measure Past Months YTD = TOTALYTD(SUM(Sheet1[EAC]),DATEADD(Sheet1[Custom Date], -1, MONTH))``

Here is my data table.

Thanks.

Helper I

## Re: pastRe: Calculate YTD using Short Month Name

Thanks.

I tried your formula and I get (Blank)

``Measure = CALCULATE(SUM(Sheet1[EAC]), FILTER(DATESYTD(Sheet1[Custom Date]), Sheet1[Custom Date] < MIN(Sheet1[Custom Date])))``

Super User I

## Re: pastRe: Calculate YTD using Short Month Name

``````Measure =
CALCULATE (
SUM ( Sheet1[EAC] ),
FILTER (
DATESYTD ( Sheet1[Custom Date] ),
Sheet1[Custom Date] < MIN ( Sheet1[Custom Date] ),
ALL(Sheet1[Custom Date], Sheet1[Filter Column2], Sheet1[Filter Column3])
)
)
``````

Replace the filter columns with the date date/month columns you are going to use in the slicer.
Note: It is advisable to use an external Dates table. It will make your formula simpler.

Proud to be a Super User!

"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."

Announcements

#### New Ranks Launched March 24th!

The time has come: We are finally able to share more details on the brand-new ranks coming to the Power BI Community!

#### ‘Better Together’ Contest Finalists Announced!

Congrats to the finalists of our ‘Better Together’-themed T-shirt design contest! Click for the top entries.

#### Arun 'Triple A' Event Video, Q&A, and Slides

Missed the Arun 'Triple A' event or want to revisit it? We've got you covered! Check out the video, Q&A, and slides now.

#### Join THE global Power Platform event series.

Attend for two days of expert-led learning and innovation on topics like AI and Analytics, powered by Dynamic Communities.

#### Community Summit North America

Innovate, Collaborate, Grow. The top training and networking event across the globe for Microsoft Business Applications

Top Solution Authors
Top Kudoed Authors