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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Average By Columns with Filter and Dates

Hello, I have many columns and I would like to average using a filter and certain columns. So I want the "Value" field to be the average by Analyte, but only when AnalyteType = "Lab", and also only for dates within the past 1.5 months (ideally, I want it to only use the last 12 months, but I didn't make a large enough sample dataset here).

 

I was trying to use the ALLEXCEPT, but I couldn't figure out how to select the AnalyteType = "Lab" nor could I figure out how to keep the date updated everytime I reload the data (which will happen once per week).

 

AnalyteType   Analyte       Value   DateEntered   Average
LabBalloons512-02-20225
FieldBalloons612-03-20225
OutsideBalloons412-04-20225
LabFaces211-05-20212
FieldFaces311-06-20212
OutsideFaces111-07-20212
LabChairs1110-01-202115
FieldChairs1210-02-202115
OutsideChairs1710-03-202115
LabChairs1512-02-202215
FieldChairs1212-03-202215
OutsideChairs1812-04-202215
14 REPLIES 14
Anonymous
Not applicable

For the final plot, I would like a clustered column chart, but since each Analyte might have really different scales, the plot would be too hard to see if the "lab" value is any different than the "outside" value. So I want to scale everything so the lab value is set to 100% and the "outside" and "field" values then show the percent difference compared with the "lab" values. So if I have a column of the average of "lab" values, then I can divide the actual values by that column and create the plot based on averages by "AnalyteType".

 

In the "table" function of the report, I can create averages by AnalyteType with the Standard Deviation as well, even applying the filter of which years to select from the page. I just don't know how to translate that to a plot. I would still need to divide the average by the "lab" average though.

Anonymous
Not applicable

I was able to get this working. I created two columns. One column has the "Lab" averages, and one has the group average, then I divide the group by the lab to get the scaled difference. Here is the code I used to create the "lab" average:

Column1 = calculate(average(Main[Value]),filter(Main,Main[Analyte]=EARLIER(Main[Analyte])),filter(Main,Main[Color]=EARLIER(Main[Color])),filter(Main,Main[AnalyteType]="Lab"),filter(Main,Main[DateEnter]>today()-365))
 
Thanks a bunch for your help.
Anonymous
Not applicable

Hi  @Anonymous ,

I created some data:

vyangliumsft_0-1669001859067.png

Here are the steps you can follow:

1. Create measure.

Measure =
AVERAGEX(FILTER(ALL('Table'),
'Table'[AnalyteType]="Lab"&&'Table'[Analyte]=MAX('Table'[Analyte])&&
'Table'[DateEntered]>=
DATE(YEAR(MAX('Table'[DateEntered]))-1,MONTH(MAX('Table'[DateEntered])),DAY(MAX('Table'[DateEntered])))&&
'Table'[DateEntered]<=MAX('Table'[DateEntered]))
,[Value])

2. Result:

vyangliumsft_1-1669001859069.png

 

Best Regards,

Liu Yang

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

Anonymous
Not applicable

The final column does not look correct. Within each "Analyte", there should be the same value. So "Balloons" should have only the "Lab" values averaged in the final column, and it should only be one value there, just repeated, like how I have it in the example in the column "Average".

daXtreme
Solution Sage
Solution Sage

Are you talking about a measure or a calculated column? Also, what does it mean "only for dates within the past 1.5 months"? For a group that you'd use for the calc of average, there may be many different dates. Which dates are you then talking about for a group of rows? And what happens if at least one of the rows in the group that you'd like to calc the average for has a date that's not within 1.5 months from now?

Anonymous
Not applicable

I don't know the difference between a measured and calculated column. I actually want the data to be averaged from the past year.

calculated column:  is computed once during dataset refresh, and stored as part of the data model. Is not impacted by user choices.

measure: is computed on the fly whenever the user interacts with the report in a way that includes that measure. Is not stored in the data model. Is impacted by user choices/filters.

Anonymous
Not applicable

Actually, that would be great if I can have a measured column which uses the inputs on the page (which pick the years/year to include in the plots). How would I be able to get the column in the datatable to account for the filters on the page that is displaying? I didn't think those two things are connected.

You cannot calculate columns from filters. That's why you need measures.

Anonymous
Not applicable

Yes, that's why I think a measure might be great. Can you show how I would do it? I looked up and saw that you put measures in the reporting/display area. What would the measure equation look like to account for all the columns I showed above? If it is on the page, then I wouldn't need the date filter because the page is already taking care of that. Thanks.

lbendlin
Super User
Super User

Avg = calculate(AVERAGE('Table'[Value]),'Table'[AnalyteType]="Lab",'Table'[DateEntered]>TODAY()-45)

lbendlin_0-1668862665039.png

Note that your sample result of "2" is not valid.

Anonymous
Not applicable

This doesn't have "Analyte" in the formula, even though we want the final values averaged by analyte (as shown in the "Avg" column in my example.

 

I tried this equation and it isn't giving the correct values. Thanks.

 

Anonymous
Not applicable

This is the simplest formula. What if I need to add one more column to average by? So not a specific value, but I also want to average by color.

Anonymous
Not applicable

I can easily make these all in a table on the report, but then I don't know how to create a plot from a table in the report area. That might be the easiest thing to do. Is that possible?

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors