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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
bswank31
Helper II
Helper II

Calculate YTD with most recent dates

Hi, I am struggling with getting my YTD amounts for my most recent dates to calculate correctly. Below is what I have. I hope this makes sense. I greatly appreciate any help I can get. 

YTD = CALCULATE(

    SUM('Expenses'[Expenditure]),

    'Expenses'[Category] IN {"YTD"}

This returns the correct amounts when I select a single month, but when I select numerous months it is adding all the YTD amounts. I only want it to give me the amount for the most recent dates.

Here is what I get when I select each month which is correct:

January

bswank31_0-1682607549623.png     

February

bswank31_1-1682607568137.png

March

bswank31_2-1682607587463.png

Here is Jan, Feb and March which is a total of all amounts for YTD and not what I want. It should be only March YTD totals.

bswank31_4-1682607673107.png

Here is the data I am using. What I want is when I select all my months, I want the YTD to only show the amount for the most recent dates. In this case, the YTD amounts for march.

bswank31_7-1682608132422.png

I also created a calculated field

YTD Total = SUMX(FILTER('Expenses', ('Expenses'[Date])= MAX('Expenses'[Date])), [YTD])

I thought this would work since it is filtering by the Category YTD but when I select just one month it is sometimes combining the YTD and Expense category.  I am confused on why it is doing that when I just have YTD filtered.

I hope this makes sense and someone can help me out. Greatly appreciate any help I can get.

THANKS!

3 REPLIES 3
bswank31
Helper II
Helper II

thank you all for your responses. After reading what you have suggestest, I have figured out this issue. 

Final YTD = CALCULATE(
    SUM('Expenses'[Expenditure]),
    'Expenses'[Category] IN {"YTD"}, 'Expenses', ('Expenses'[Date])= MAX('Expenses'[Date]))
Ashish_Mathur
Super User
Super User

Hi,

Create a Calendar Table with calculated column formulas for Year, Month name and Month number.  Sort the Month name by the Month number.  Create a relationship (Many to One and Single) from the Date column of the Expenses table to the Date column of the Calendar Table.  Ceate 2 slicer - one for Year and another for Month (Ensure that both these fields are dragged from the Calendar Table).  Write this measure

YTD sales = calculate(SUM('Expenses'[Expenditure]),datesytd(calendar[Date],"31/12"))

Hope this helps.


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

In order for this to work you cannot neglect the year.  

 

Find the maximum YearMonth that has data, and then present the sum of values for that YearMonth.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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