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 Measure with filter

Hi,

 

I want to calculate the average days it take to complete an order with product type 'Computer'. How can I calculate that in a measure?

This is a sample of my data:

OrderID   OrderDate      OrderCompleteDate     Product     
11-11-20215-11-2021Computer
24-11-20217-11-2021Computer
37-11-202111-11-2021Computer
1 ACCEPTED SOLUTION
ryan_mayu
Super User
Super User

@Anonymous 

you can create a column and measure

days = DATEDIFF('Table'[OrderDate      ],'Table'[OrderCompleteDate     ],DAY)

Measure = AVERAGEX(FILTER('Table','Table'[Product     ]="Computer"),'Table'[days])

 

or  you can create a measure directly.

Measure 2 = 
VAR tbl=ADDCOLUMNS(FILTER('Table','Table'[Product     ]="Computer"),"day2",DATEDIFF('Table'[OrderDate      ],'Table'[OrderCompleteDate     ],DAY))
return AVERAGEX(tbl,[day2])

pls see the attachment below.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

6 REPLIES 6
Ashish_Mathur
Super User
Super User

Hi,

You may create a calculated column formula to calculate the difference between the 2 date columns.  Give a heaing to that column as Days.  Then write this measure

Measure = average9Data[Days])

To your table visual, drag Product and the Measure. 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
CNENFRNL
Community Champion
Community Champion

Screenshot 2021-11-23 110053.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

ryan_mayu
Super User
Super User

@Anonymous 

you can create a column and measure

days = DATEDIFF('Table'[OrderDate      ],'Table'[OrderCompleteDate     ],DAY)

Measure = AVERAGEX(FILTER('Table','Table'[Product     ]="Computer"),'Table'[days])

 

or  you can create a measure directly.

Measure 2 = 
VAR tbl=ADDCOLUMNS(FILTER('Table','Table'[Product     ]="Computer"),"day2",DATEDIFF('Table'[OrderDate      ],'Table'[OrderCompleteDate     ],DAY))
return AVERAGEX(tbl,[day2])

pls see the attachment below.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Anonymous
Not applicable

@ryan_mayu Thanks, question: in the second measure, why do you define "day2"?

@Anonymous 

like @manikumar34 mentioned, just want to differerntiate from the day column in the first solution.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




@Anonymous ,

 

days2 is defined here as a column for the difference of those tow date columns. You can use othe column name instaed. One first measure dates difference created as a column whereas on 2nd calculation written as a measure, so he is using variable and ADDCOLUMNS functions to define that on measure and use that on AVERAGEX





If this helps, Appreciate your KUDOS!
Did I answer your question? Mark my post as a solution!


Proud to be a Super User!




Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

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

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.