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
LeoST
Frequent Visitor

Calculate YTD based on an existing Measure

Hello all,

my table looks like this:

CostStartEnd
2001.05.202031.12.2020
4001.02.202031.11.2021

 

Now I've created a measure that shows me the costs per month for each month already:

 

 

Total Cost Monthly = 
CALCULATE(
	SUM('DataTable'[Cost]), 
    FILTER(
        ALLSELECTED(DataTable), 
        (DataTable[Start].[Date] <= MAX(DataTable[Start].[Date]) && ((DataTable[End].[Date] >= MAX(DataTable[Start].[Date])) || (ISBLANK(DataTable[End].[Date]) ))
    )
))

 

 

This works fine when I use the Start Column as a axis and shows me the sum of all costs for each month.

However I can't get the total cost for a year because the YTD function based on my Measure "Total Cost Monthly" and the start date. This calculates almost the same values as my "Total Cost Monthly" measure.

 

Is there any trick to get the YTD working or any other way to calculate the yearly values?

1 ACCEPTED SOLUTION

@LeoST , I tried this on current employee

Measure = CALCULATE(sumx(SUMMARIZE('Date', 'Date'[Date],"_1",[Current Employees]),[_1]),filter(ALLSELECTED('Date'),'Date'[Date] <=max('Date'[Date])))

 

you might have to use month year

Measure = CALCULATE(sumx(SUMMARIZE('Date', 'Date'[Month Year],"_1",[Current Employees]),[_1]),filter(ALLSELECTED('Date'),'Date'[Date] <=max('Date'[Date])))

View solution in original post

5 REPLIES 5
Anonymous
Not applicable

Yeah, there is a trick. It'll all be working fine if you start building correct models and use dedicated Date tables instead of the automatic ones. Automatic date tables are only for the simplest of models and should be avoided in professional development like the plague.
amitchandak
Super User
Super User

@LeoST ,

Can you share sample output in table format? Or a sample pbix after removing sensitive data.

 

Refer if these can help

https://community.powerbi.com/t5/Community-Blog/HR-Analytics-Active-Employee-Hire-and-Termination-tr...

or this file

https://www.dropbox.com/s/bqbei7b8qbq5xez/leavebetweendates.pbix?dl=0

Hello @amitchandak 

Thanks for your quick response and the link - it was very helpful!

My datamodel now looks almost identical as your HR example. The formula for "Current Employees" also works perfectly for me except that I need the sum and not count since I calculate with costs and not employees. So that gives me reliably the total costs per month for each month individually.

Now what I try to do is something like a running total over that adopted "Current Employees" measure (doesn't make any sence for employee counts but in my case with costs it does and gives me the total costs in that year that).

Example:

2020-09-21_11h46_15.png

 So in July 20 I've -136 Cost and in May 21 I've -140 Cost. My measure should show me know the total cost for a year like 2020 or 2021 (so I need to sum up the values again). 

@LeoST , I tried this on current employee

Measure = CALCULATE(sumx(SUMMARIZE('Date', 'Date'[Date],"_1",[Current Employees]),[_1]),filter(ALLSELECTED('Date'),'Date'[Date] <=max('Date'[Date])))

 

you might have to use month year

Measure = CALCULATE(sumx(SUMMARIZE('Date', 'Date'[Month Year],"_1",[Current Employees]),[_1]),filter(ALLSELECTED('Date'),'Date'[Date] <=max('Date'[Date])))

Thanks a lot, that works perfectly! 

I think I understood now how to handle dates in Power BI in the right way - thanks for that!

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.

Top Solution Authors