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