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
water-guy-5
Helper III
Helper III

Calculate average since a specific date (SAMPLE DATA INCLUDED)

Hello,

I posted last week but have provided a better layout of what it is I am trying to solve.

I have a list of facilities, and each one has a date for whena certain "limit" was established. Basically saying that on the "Submittal Date", we are now tracking certain values to monitor exceedances. I have also calculated the difference from the submittal date and today as I thought that might help with what I am trying to solve. For this example, lets use the highlighted row and call this FACILITY A.

waterguy5_0-1670263093014.png

So, my goal is to find the average result since the day of the submittal. However, I have a table with daily results since the creation of the facility. So, lets say that I have daily readings since the end of 2020 (see below). What I want is the average of the discharge column only from the submittal date, in this case 7/21/2022, or the last 137 days (as seen in the far right column above).

waterguy5_1-1670263329517.png

 

If I were to make a measure, all I am able to solve is for a certain number of days. This does not allow me to customize the averages based on each facilities differing submittal date. The average result will change if I do this versus what I want which is to solve for the average since the submittal date.

Any help?

1 ACCEPTED SOLUTION
v-yueyunzh-msft
Community Support
Community Support

Hi , @water-guy-5 

According to your description, you want to calculate the "average since a specific date" , I do not know your table field and the relationships so i create test data like this:

vyueyunzhmsft_0-1670291959696.png

Here are the steps that i hope it can help you :
(1)We can create a measure like this:

Average = var _cur_SubmittalDate = MAX('FACILITY'[Submittal Date])
var _curFacility = MAX('FACILITY'[FACILITY])
var _days = SUM('FACILITY'[Days Since Submittal])
var _t = FILTER( ALLSELECTED('Table') , 'Table'[FACILITY] = _curFacility && 'Table'[Date] <= _cur_SubmittalDate && 'Table'[Date]>_cur_SubmittalDate - _days)
return
DIVIDE(SUMX(_t , [Discharge]),_days)

(2)Then we can put it on the visual and the result is as follows:

vyueyunzhmsft_1-1670292386312.png

 

If this method does not meet your needs, you can provide us with your special sample data and the desired output sample data in the form of tables, so that we can better help you solve the problem.

Thank you for your time and sharing, and thank you for your support and understanding of PowerBI! 

 

Best Regards,

Aniya Zhang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

 

View solution in original post

1 REPLY 1
v-yueyunzh-msft
Community Support
Community Support

Hi , @water-guy-5 

According to your description, you want to calculate the "average since a specific date" , I do not know your table field and the relationships so i create test data like this:

vyueyunzhmsft_0-1670291959696.png

Here are the steps that i hope it can help you :
(1)We can create a measure like this:

Average = var _cur_SubmittalDate = MAX('FACILITY'[Submittal Date])
var _curFacility = MAX('FACILITY'[FACILITY])
var _days = SUM('FACILITY'[Days Since Submittal])
var _t = FILTER( ALLSELECTED('Table') , 'Table'[FACILITY] = _curFacility && 'Table'[Date] <= _cur_SubmittalDate && 'Table'[Date]>_cur_SubmittalDate - _days)
return
DIVIDE(SUMX(_t , [Discharge]),_days)

(2)Then we can put it on the visual and the result is as follows:

vyueyunzhmsft_1-1670292386312.png

 

If this method does not meet your needs, you can provide us with your special sample data and the desired output sample data in the form of tables, so that we can better help you solve the problem.

Thank you for your time and sharing, and thank you for your support and understanding of PowerBI! 

 

Best Regards,

Aniya Zhang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

 

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.