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

July 28 - August 9 | Final Round of the Power BI Dataviz World Championships. This is your chance. Learn more

Reply
UK_User123456
Resolver I
Resolver I

Averages

Hi All,

 

I have two tables that are connected through a calendar table. The problem I am having is that in the first table I need to calculate an average of the last 12 months only even if the dates go back further and then divide that average by the total number of people in the second table e.g.

 

First Table

Department

Department     Staff number     Start Date

1                         12345              10/10/2015

2                         56745              01/09/2019

3                         10101              15/10/2018

4                         20202              20/01/2016

 

Second Table

Staff

Department     Staff number     Leaving Date

1                         12345              01/03/2017

2                         56745              22/09/2019

3                         10101              13/04/2020

4                         20202              19/10/2019

 

The calculation I have for the first table to calculate the average is

Dep =
var MinDate = MIN('Calendar'[Date])
var MaxDate = MAX('Calendar'[Date])
var DepTotal =
    CALCULATE( DIVIDE(COUNT(Department[Staff Number]),DISTINCTCOUNT(Department[Staff Number])),
          Department[Start Date]>= MinDate
        && Department[Start Date] <= MaxDate,
        NOT(ISBLANK(Headcount[Start Date]))
    )
Return
DepTotal
 
The calculation I have for the second table is:
CStaff =
var MinDate = MIN('Calendar'[Date])
var MaxDate = MAX('Calendar'[Date])
var StaffTotal =
    CALCULATE( COUNT(Staff[Staff Number]),
          Staff[Leaving Date]>= MinDate
        && Staff[Leaving Date] <= MaxDate,
        NOT(ISBLANK(Staff[Leaving Date]))
    )
Return
StaffTotal
 
Any help would would be great.
 
TIA
3 REPLIES 3
Manoj_Nair
Solution Supplier
Solution Supplier

@UK_User123456 - Please check this out, let me know if this works. If this fix your problem, please tick this a solution and a thumps up.

 

Staff 12 MONTHS = 
CALCULATE(
    COUNTROWS('DEPARTMENT'),
    FILTER(
        ALL('Calendar'[Date]),
        'Calendar'[Date] > TODAY() - 365 && 'Calendar'[Date] <= TODAY()
    ),
    RELATEDTABLE('DEPARTMENT')
)
Total Staff = COUNTROWS('STAFF')
Average = 
DIVIDE(
    [Staff 12 MONTHS],
    [Total Staff],
    0
)

 

Hi @Manoj_Nair ,

 

How would the calculation work if put into the calculation I currently have in my post, as I need to be able to show these split down by month, so showing the split out by month in a matrix table?

 

Thanks

Hi @Manoj_Nair ,

 

Many thanks for this, is this meant to be two seperate calculation measures or one?

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

Fabric Community Sticker Design Challenge Barcelona Carousel

Fabric Community Sticker Challenge - Barcelona 2026

If you love stickers, then you will definitely want to check out our community sticker challenge, Barcelona edition!

July Power BI Update Carousel

Power BI Monthly Update - July 2026

Check out the July 2026 Power BI update to learn about new features.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Solution Authors