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
Ritaf
Responsive Resident
Responsive Resident

Average of difference between columns with filters

Hi,

I have a table as on the picture and need to calculate the average difference between the start date and the end date, by supplier excluding rows with a start date after the end date and excluding rows whose start date/end date is"31/12/1899".
I tried the dax below, but it gives me incorrect results, how can I correct it?

TestAverage =
CALCULATE(AVERAGEX('Sheet1',
DATEDIFF('Sheet1'[StartDate],Sheet1[EndDate],DAY)),
FILTER(Sheet1,Sheet1[StartDate]<Sheet1[EndDate] && Sheet1[StartDate]<>31/12/1989 && Sheet1[EndDate]<>31/12/1989))
Link to Samle File:Sample.pbix testD.JPG
1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi,

Please try the below measure.

 

TestAverage =
AVERAGEX (
    FILTER (
        Sheet1,
        Sheet1[StartDate] < Sheet1[EndDate]
            && NOT ( Sheet1[StartDate] = DATE ( 1899, 12, 31 ) )
                && NOT ( Sheet1[EndDate] = DATE ( 1899, 12, 31 ) )
    ),
    DATEDIFF ( 'Sheet1'[StartDate], Sheet1[EndDate], DAY )
)

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


View solution in original post

2 REPLIES 2
Ritaf
Responsive Resident
Responsive Resident

It worked !! Thank you!

Jihwan_Kim
Super User
Super User

Hi,

Please try the below measure.

 

TestAverage =
AVERAGEX (
    FILTER (
        Sheet1,
        Sheet1[StartDate] < Sheet1[EndDate]
            && NOT ( Sheet1[StartDate] = DATE ( 1899, 12, 31 ) )
                && NOT ( Sheet1[EndDate] = DATE ( 1899, 12, 31 ) )
    ),
    DATEDIFF ( 'Sheet1'[StartDate], Sheet1[EndDate], DAY )
)

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


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.