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
neuro_fun
Helper I
Helper I

Measure not working, when calculated column worked. Using Average.

I have a table with the columns "Value", "Analyte", "Color", "AnalyteType" and "DateEnter". I created a calculated column that averages by all those groups and takes only the last 12 months of data. I would like to move this to a measure though, so I can change which data is used on the fly.

 

ValueAnalyteColorAnalyteTypeDateEnter
5.44BalloonBlueLab2022/05/04
62.5CarRedLab2022/03/11
11.5CarPurpleOutside2022/02/08
78.1ChairBlueIndoor2022/04/22

 

Here is the calculated column that works:

 

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))

 

Here is the measure I tried:

 

MeasureDiffs =
average(calculate(average(Main[Final]),filter(Main,Main[Analyte]=EARLIER(Main[Analyte])),filter(Main,Main[Color]=EARLIER(Main[Color])),filter(Main,Main[AnalyteType]="Lab")))
 
I get the error "The AVERAGE function only accepts a column reference as an argument". I don't understand because it did work as a column in the data table. Any ideas?
1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@neuro_fun , Try like

 

calculate(average(Main[Final]),filter(allselected(Main),Main[Analyte]=Max(Main[Analyte]) &&  Main[Color]=Max (Main[Color]) && Main[AnalyteType]="Lab"))

View solution in original post

2 REPLIES 2
amitchandak
Super User
Super User

@neuro_fun , Try like

 

calculate(average(Main[Final]),filter(allselected(Main),Main[Analyte]=Max(Main[Analyte]) &&  Main[Color]=Max (Main[Color]) && Main[AnalyteType]="Lab"))

That worked great. Why use the "Max" instead of "Earlier"?

Helpful resources

Announcements
PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.