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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
Anonymous
Not applicable

Calculate Average with Filter in DAX not working

I have a table with a Working Days column, which is integer type, and a Latest Action Date column with date (01/01/2020). I want a DAX measure to calculate the average but only for 2020 dates.

 

 

Latest Submission DateLatest Action Date

Working Days

4/1/20204/4/20204
4/3/20204/5/20202
1/4/20211/5/20211

 

 

 

I tried the following measures I wrote:

 

2020 Avg SLA =
CALCULATE ( AVERAGE ( 'Pivoted Audit Log'[Working Days] ), 'Pivoted Audit Log'[Latest TM Action Date] < 01/01/2021 )
 
2020 Avg SLA Fixed = CALCULATE(
AVERAGE('Pivoted Audit Log'[Working Days]),
FILTER('Pivoted Audit Log', 'Pivoted Audit Log'[Latest TM Action Date] < 01/01/2021))

 

 

Got this error though both times: 

 

Error Message:
MdxScript(Model) (35, 60) Calculation error in measure 'Pivoted Audit Log'[2020 Avg SLA Fixed]: DAX comparison operations do not support comparing values of type Text with values of type Number. Consider using the VALUE or FORMAT function to convert one of the values.

 

 

My objective:

 

A measure that calculates the average in a column, but only for year 2020, and then, another measure that calculates the average in a column but only for year 2021

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@Anonymous , you can create a new column like

 


Work Day =
Var _end = if([Latest Action Date] > Date(2020,12,31),Date(2020,12,31), [Latest Action Date])
return
COUNTROWS(FILTER(ADDCOLUMNS(CALENDAR(Table[Latest Submission Date])_end),"WorkDay", if(WEEKDAY([Date],2) <6,1,0)),[WorkDay] =1))

 

 

or measure with some group by row id

Work Day =
Var _end = if(max([Latest Action Date]) > Date(2020,12,31),Date(2020,12,31), max[Latest Action Date]))
return
AverageX(Values(Table[RowID]), COUNTROWS(FILTER(ADDCOLUMNS(CALENDAR(max(Table[Latest Submission Date]),_end),"WorkDay", if(WEEKDAY([Date],2) <6,1,0)),[WorkDay] =1)))

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

1 REPLY 1
amitchandak
Super User
Super User

@Anonymous , you can create a new column like

 


Work Day =
Var _end = if([Latest Action Date] > Date(2020,12,31),Date(2020,12,31), [Latest Action Date])
return
COUNTROWS(FILTER(ADDCOLUMNS(CALENDAR(Table[Latest Submission Date])_end),"WorkDay", if(WEEKDAY([Date],2) <6,1,0)),[WorkDay] =1))

 

 

or measure with some group by row id

Work Day =
Var _end = if(max([Latest Action Date]) > Date(2020,12,31),Date(2020,12,31), max[Latest Action Date]))
return
AverageX(Values(Table[RowID]), COUNTROWS(FILTER(ADDCOLUMNS(CALENDAR(max(Table[Latest Submission Date]),_end),"WorkDay", if(WEEKDAY([Date],2) <6,1,0)),[WorkDay] =1)))

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Feb2025 NL Carousel

Fabric Community Update - February 2025

Find out what's new and trending in the Fabric community.