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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
Yoshimitsu411
Resolver I
Resolver 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

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

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
amitchandak
Super User
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

 

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

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.

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."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu.

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

 

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."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu.

Thanks @danextian 

 

I tried your formula and get the error - Too many arguments were passed to the FILTER function. The maximum argument count for the function is 2.

 

FilterError.PNG

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

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

 

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.

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/

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

 

You are welcome.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
stretcharm
Memorable Member
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.

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

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

Find out what's new and trending in the Fabric Community.