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
TomLU123
Helper III
Helper III

Calculate the Average Headcount of the period

Dear experts,

 

I have a dataset like below. We wish to create a measure to calculate the Average Headcount of the period by Sumimg the not empty headcount of the erlist date and not empty headcount of the latest date's the user choose, and then divided by 2. 

  

For example, if the user choose 6/3/2018 to 6/10/2018, the Average Headcount of the period=  (5100+4500)/2. 

If the user choose 6/6/2018 to 6/11/2018, the Average Headcount of the period = (5200+5000)/2

 

DateHeadcount
6/1/20185000
6/2/20184500
6/3/2018 
6/4/2018 
6/5/20185100
6/6/20185200
6/7/20185400
6/8/20185200
6/9/20184900
6/10/20184500
6/11/20185000
6/12/20184700

 

How should we write the expression to achieve that?

Many thanks!


Best regards,

Tom

1 ACCEPTED SOLUTION
Zubair_Muhammad
Community Champion
Community Champion

@TomLU123

 

You can use this MEASURE

 

Measure =
VAR MyMin =
    CALCULATE (
        MIN ( [Headcount] ),
        CALCULATETABLE ( FIRSTDATE ( Table1[Date] ), Table1[Headcount] <> BLANK () )
    )
VAR MyMax =
    CALCULATE (
        MAX ( [Headcount] ),
        CALCULATETABLE ( LASTDATE ( Table1[Date] ), Table1[Headcount] <> BLANK () )
    )
RETURN
    ( MyMin + MyMax )
        / 2

Regards
Zubair

Please try my custom visuals

View solution in original post

2 REPLIES 2
Zubair_Muhammad
Community Champion
Community Champion

@TomLU123

 

You can use this MEASURE

 

Measure =
VAR MyMin =
    CALCULATE (
        MIN ( [Headcount] ),
        CALCULATETABLE ( FIRSTDATE ( Table1[Date] ), Table1[Headcount] <> BLANK () )
    )
VAR MyMax =
    CALCULATE (
        MAX ( [Headcount] ),
        CALCULATETABLE ( LASTDATE ( Table1[Date] ), Table1[Headcount] <> BLANK () )
    )
RETURN
    ( MyMin + MyMax )
        / 2

Regards
Zubair

Please try my custom visuals

Hi Zubair,  @Zubair_Muhammad

 

Just a further quetsion, what if the raw data set is like below. The database will refresh the active employee ID in following table once a day. The "Report Date" is the refresh date. 

 

For example, on 6/1/2018 and 6/2/2018, they are empty which means there are no employees.

On 6/3/2018, there are 4 employees joined.

On 6/4/2018, there are 4 employeess (no one join or left).

On 6/5/2018, there are 3 employees (one left).

 

I sitll wish to create a to create a measure to calculate the Average Headcount of the period by Sumimg the not empty headcount of the erlist date and not empty headcount of the latest date's the user choose, and then divided by 2.

 

For example, if the user choose 6/1/2018 to 6/5/2018, the Average Headcount of the period= (4+3)/2.

If the user choose 6/3/2018 to 6/4/2018, the Average Headcount of the period = (4+4)/2

 

Report DateEmployee ID
6/1/2018 
6/2/2018 
6/3/2018111
6/3/2018222
6/3/2018333
6/3/2018444
6/4/2018111
6/4/2018222
6/4/2018333
6/4/2018444
6/5/2018111
6/5/2018

222

6/5/2018

333

 

How should we modify the Expression to achieve that?

Many thanks!

 

Best regards,

Tom

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.