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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

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
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.