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

Calculating the Average Value of the Earliest and Latest Date the user chose

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 headcount of the erlist date's headcount and latest date's the user choose, and then divided by 2. 

 

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

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

DateHeadcount
6/1/20185000
6/2/20184500
6/3/20184800
6/4/20184900
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 experssion to achieve that?

Many thanks for your help!

 

Best regards,

Tom

1 ACCEPTED SOLUTION
TomMartens
Super User
Super User

Hey,

 

assuming that the user selects the dates using a date slicer, this measure does what you are looking for:

Measure = 
var selectedDates = ALLSELECTED(Table2[Date])
var minDate = MINX(selectedDates,'Table2'[Date])
var maxDate = MAXX(selectedDates,'Table2'[Date])
return
(CALCULATE(SUM(Table2[Headcount]),'Table2'[Date] = minDate)
+ CALCULATE(SUM(Table2[Headcount]),'Table2'[Date] = maxDate))/2

Here is a little screenshot:

image.png

 

Regards,

Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

View solution in original post

2 REPLIES 2
TomMartens
Super User
Super User

Hey,

 

assuming that the user selects the dates using a date slicer, this measure does what you are looking for:

Measure = 
var selectedDates = ALLSELECTED(Table2[Date])
var minDate = MINX(selectedDates,'Table2'[Date])
var maxDate = MAXX(selectedDates,'Table2'[Date])
return
(CALCULATE(SUM(Table2[Headcount]),'Table2'[Date] = minDate)
+ CALCULATE(SUM(Table2[Headcount]),'Table2'[Date] = maxDate))/2

Here is a little screenshot:

image.png

 

Regards,

Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

Hi Tom,

 

Just a further question:what if some of the date's headcount is empty. 

 

We still wish to create a measure to calculate the Average Headcount of the period by Sumimg the not empty headcount of the earliest date and not empty headcount of latest date 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/5/2018 to 6/11/2018, the Average Headcount of the period = (5100+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 modify the experssion to achieve that?

Many thanks!


Best regards,

Tom

 

@TomMartens

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.