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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
kweibelt
Frequent Visitor

Calculate Average with filters and If statements

I am a bit out of practice and have recently been using PBI again. I have a column that calculates if we are before or past the due date in days:

Schedule Adhereance =

IF(ISBLANK(Request[Completed]), 0,

if(

    AND(

        ISBLANK(Request[Due]), ISBLANK(Request[OriginalDue])),

        -1*(Request[TargetComplete] - Request[Completed]),

        if(

        ISBLANK(Request[Due]),

        -1*(Request[OriginalDue] - Request[Completed]),

            -1*(Request[Due] - Request[Completed])))

            )

 

I need for it to also filter based on the Status UAT or Done. I have tried many variations but am unable to get this to work.

 

For each record I expect to see the number of days but if I am using it in the dashboard I expect to see the average number of days.

1 ACCEPTED SOLUTION
tamerj1
Super User
Super User

Ji @kweibelt 

Please try creating a measure as follows 

Average Schedule Adhereance =
AVERAGEX (
Request,
IF (
ISBLANK ( Request[Completed] )
&& Request[Statis] IN { "UAT", "Done" },
0,
IF (
AND ( ISBLANK ( Request[Due] ), ISBLANK ( Request[OriginalDue] ) ),
( Request[Completed] - Request[TargetComplete] ),
IF (
ISBLANK ( Request[Due] ),
( Request[Completed] - Request[OriginalDue] ),
( Request[Completed] - Request[Due] )
)
)
)
)

View solution in original post

3 REPLIES 3
kweibelt
Frequent Visitor

@tamerj1 Thank you SO much! This is perfect. I completly forgot about Averagex and that was causing issues for me. 

tamerj1
Super User
Super User

Ji @kweibelt 

Please try creating a measure as follows 

Average Schedule Adhereance =
AVERAGEX (
Request,
IF (
ISBLANK ( Request[Completed] )
&& Request[Statis] IN { "UAT", "Done" },
0,
IF (
AND ( ISBLANK ( Request[Due] ), ISBLANK ( Request[OriginalDue] ) ),
( Request[Completed] - Request[TargetComplete] ),
IF (
ISBLANK ( Request[Due] ),
( Request[Completed] - Request[OriginalDue] ),
( Request[Completed] - Request[Due] )
)
)
)
)

lbendlin
Super User
Super User

Please provide sample data that covers your issue or question completely.
https://community.powerbi.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-Forum/ba-...
Please show the expected outcome based on the sample data you provided.

https://community.powerbi.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447523

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

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