cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Yoshimitsu411 Helper I
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?

 

Capture.PNG

 

Thank you for any suggestions.

 

Yoshi

2 ACCEPTED SOLUTIONS

Accepted Solutions
Super User IV
Super User IV

Re: pastRe: Calculate YTD using Short Month Name

Hi,

You may download my PBI file from here.

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

Yoshimitsu411 Helper I
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

 

View solution in original post

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

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.

https://www.youtube.com/watch?v=5WGOTsYngCI

Super User IV
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://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

 





Did I answer your question? Mark my post as a solution! Appreciate your Kudos!!
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
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 ))





Did I answer your question? Mark my post as a solution! Appreciate your Kudos!!
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


Yoshimitsu411 Helper I
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.

 

Capture.PNG

 

 

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

 





Did I answer your question? Mark my post as a solution! Appreciate your Kudos!!
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
Super User I

Re: pastRe: Calculate YTD using Short Month Name

Hi @Yoshimitsu411 ,

 

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





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

Proud to be a Super User!







"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
www.linkedin.com/in/danebelarminocpa
Yoshimitsu411 Helper I
Helper I

Re: pastRe: Calculate YTD using Short Month Name

Thanks for your reply.

 

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

 

Here is some sample data.

 

AssetPartner Project IDProject NameJAN EACFEB EACMAR EACAPR EACMAY EACJUN EACJUL EACAUG EACSEP EACOCT EACNOV EACDEC EAC
ContosoCON-TOSO-001Lorem ipsum dolor sit amet123         
ContosoCON-TOSO-002consectetur adipiscing elit. Donec rhoncus234         
ContosoCON-TOSO-003arius diam consequat a. Maecenas eget345         
ContosoCON-TOSO-004attis ex vestibulum in. Nulla ipsum velit456         
ContosoCON-TOSO-005t tellus eget facilisis. Fusce posuere maximus leo567         
ContosoCON-TOSO-006 sapien sodales purus, at ornare odio 678         
ContosoCON-TOSO-007am laoreet pellentesque condimentum. Cras ac pellentesque odio789         
ContosoCON-TOSO-008auris sapien sodales purus, at ornare8910         
ContosoCON-TOSO-009olutpat ac dignissim eget, dictum vitae magna. Duis et metus91011         
ContosoCON-TOSO-010placerat tellus eget facilisis101112         
               

 

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.

 

Capture1.PNG

 

Thanks.

Yoshimitsu411 Helper I
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
Super User I

Re: pastRe: Calculate YTD using Short Month Name

Hi @Yoshimitsu411 ,

 

 

Please modify your formula to this:

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.






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

Proud to be a Super User!







"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
www.linkedin.com/in/danebelarminocpa

Helpful resources

Announcements
New Ranks Launched March 24th!

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!

‘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

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 Microsoft Power Platform event series.

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

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