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
stben
Regular Visitor

YTD Average with Slicers

Hi!

 

I have a table with Headcount and People Costs by month for three organizations.  I am trying to create a measure that calculates the YTD average headcount that works with a slicer for organization.  An example of the data is below.

 

Fiscal MonthOrganizationValuesActual
JanuarySharedHeadcount5
JanuaryPremierHeadcount10
JanuaryMCSHeadcount15
FebruarySharedHeadcount6
FebruaryPremierHeadcount11
FebruaryMCSHeadcount16
JanuarySharedPeople Cost500
JanuaryPremierPeople Cost1000
JanuaryMCSPeople Cost1500
FebruarySharedPeople Cost600
FebruaryPremierPeople Cost1100
FebruaryMCSPeople Cost1600

 

The measure I have written is

Actual YTD HC Avg = TOTALYTD( CALCULATE( AVERAGE( 'AAD CPH'[Actual] ) , 'AAD CPH'[Values] = "Headcount" ) , 'Calendar'[Fiscal Month] , "06/01/2017" )

 

*Calendar is my date table and is mapped to my fiscal month through a mapping table*

 

It works fine when I have a single organization selected in my slicer.  For example, February YTD HC Avg for Shared is returning 5.5 ( Average of 5 & 6). 

 

However, when I select all organizations in the slicer to show the Total, I get 10.5 instead of the expected 31.5 (Average of 30 & 33).  I know it's calculating the average of all 6 numbers to get 10.5, but I don't know how to write the formula to cumulate the numbers within a fiscal month before taking the average.

2 REPLIES 2
stben
Regular Visitor

Well it may not be the most elegant solution, but it seems to work!  I removed the Average from the equation and instead divide by a TotalYTD of a DistinctCount.  Still interested in more straightforward ways of accomplishing this Smiley Happy

 

Actual YTD HC Avg = ( TOTALYTD( CALCULATE( SUM( 'AAD CPH'[Actual] ) , 'AAD CPH'[Values] = "Headcount" ) , 'Calendar'[Fiscal Month] , "06/01/2017" )) / CALCULATE( TOTALYTD( DISTINCTCOUNT( 'Calendar'[Fiscal Month] ) , 'Calendar'[Fiscal Month] , "06/01/2017" ) )

CheenuSing
Community Champion
Community Champion

Hi @stben

 

You could try the following approach

 

1. Create a measure called as SumActual = CALCULATE( SUM( 'AAD CPH'[Actual] ) , 'AAD CPH'[Values] = "Headcount" )

2. Create the average measure as AvgActual = AVERAGEX('Calendar', [SumActual])

3. Depending on the slicer for Organization and Date filter you will get the Average value as you wanted.

 

I am attaching a sample screenshot with the above approach

 

Capture.GIF

 

If this works for you please accept this as a solution and also give KUDOS.

 

Cheers

 

CheenuSing

Did I answer your question? Mark my post as a solution and also give KUDOS !

Proud to be a Datanaut!

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.