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

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

Reply
vika160
Helper III
Helper III

Average auto-Calculation

Hi All,

I am struggiling to figure out why the Average is not calcucated properly:

_Avg Days Open-Complaints = Calculate(AVERAGE(COMPLAINTS[_Days Open]), NOT ISBLANK(COMPLAINTS[_Days Open]))
 
if I just calculate totals and divide them I an getting the different result.
on left side is Average function, on the right is "manual" calculation.
Can someone help/direct/explain this?
 
Thank you very much!
 
PowerBI Average.PNG

 

 

 

1 ACCEPTED SOLUTION
mahoneypat
Microsoft Employee
Microsoft Employee

The main reason for the difference is that your column for days open returns blank if the complaint is closed on the same day it's opened.  If you remove the = from <= in that expression, the results get much closer.  The small difference after that is because you have one complaint with a closed date < open date.  Since that one included in the complaint count but not the days open total, the result is incorrect.  I believe the correct result is 147.06.  

 

A couple things:

 

You don't need the CALCULATE around your _TotalDaysOpen and _TotalComplaints measures.

 

I would rewrite your column like this (to be more efficient).

 

Days Open Column =
VAR vCloseDate =
    IF (
        ISBLANK ( COMPLAINTS[Closed_Date] ),
        TODAY (),
        COMPLAINTS[Closed_Date]
    )
VAR vDaysOpen =
    DATEDIFF (
        COMPLAINTS[Opened_Date],
        vCloseDate,
        DAY
    )
RETURN
    IF (
        vDaysOpen >= 0,
        vDaysOpen,
        BLANK ()
    )

 

 

You also don't need the column and can do it all in a measure.  However, if you plan to use that column in a visual axis or legend, you need it.

 

New Avg Open =
VAR vSummary =
    ADDCOLUMNS (
        SUMMARIZE (
            COMPLAINTS,
            COMPLAINTS[ID],
            COMPLAINTS[Opened_Date],
            COMPLAINTS[Closed_Date]
        ),
        "cDaysOpen",
            DATEDIFF (
                COMPLAINTS[Opened_Date],
                IF (
                    ISBLANK ( COMPLAINTS[Closed_Date] ),
                    TODAY (),
                    COMPLAINTS[Closed_Date]
                ),
                DAY
            )
    )
RETURN
    AVERAGEX (
        FILTER (
            vSummary,
            [cDaysOpen] >= 0
        ),
        [cDaysOpen]
    )

 

 

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

4 REPLIES 4
vika160
Helper III
Helper III

Hi Pat,

Thank you very much for so detailed explanations.

I had a suspicion that standard AVE function was affected by Blank duration for Complaints with the same Start and End dates. it looks it was correct thought.

I really appreciated your hints on rewrinting the formulas.

 

Thank you very much.

Victoria

mahoneypat
Microsoft Employee
Microsoft Employee

The main reason for the difference is that your column for days open returns blank if the complaint is closed on the same day it's opened.  If you remove the = from <= in that expression, the results get much closer.  The small difference after that is because you have one complaint with a closed date < open date.  Since that one included in the complaint count but not the days open total, the result is incorrect.  I believe the correct result is 147.06.  

 

A couple things:

 

You don't need the CALCULATE around your _TotalDaysOpen and _TotalComplaints measures.

 

I would rewrite your column like this (to be more efficient).

 

Days Open Column =
VAR vCloseDate =
    IF (
        ISBLANK ( COMPLAINTS[Closed_Date] ),
        TODAY (),
        COMPLAINTS[Closed_Date]
    )
VAR vDaysOpen =
    DATEDIFF (
        COMPLAINTS[Opened_Date],
        vCloseDate,
        DAY
    )
RETURN
    IF (
        vDaysOpen >= 0,
        vDaysOpen,
        BLANK ()
    )

 

 

You also don't need the column and can do it all in a measure.  However, if you plan to use that column in a visual axis or legend, you need it.

 

New Avg Open =
VAR vSummary =
    ADDCOLUMNS (
        SUMMARIZE (
            COMPLAINTS,
            COMPLAINTS[ID],
            COMPLAINTS[Opened_Date],
            COMPLAINTS[Closed_Date]
        ),
        "cDaysOpen",
            DATEDIFF (
                COMPLAINTS[Opened_Date],
                IF (
                    ISBLANK ( COMPLAINTS[Closed_Date] ),
                    TODAY (),
                    COMPLAINTS[Closed_Date]
                ),
                DAY
            )
    )
RETURN
    AVERAGEX (
        FILTER (
            vSummary,
            [cDaysOpen] >= 0
        ),
        [cDaysOpen]
    )

 

 

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


amitchandak
Super User
Super User

@vika160 , formula seems fine. Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data.

with expected values

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

Vote for your favorite vizzies from the Power BI World Championship submissions!

Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

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

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 Power BI update to learn about new features.

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.