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

The Power BI Data Visualization World Championships is back! It's time to submit your entry. Live now!

Reply
Anonymous
Not applicable

Average calculation based on dates

Hi 
I need to calculate the average time of these priorities and something is missing in my equation because it should only include the dates if "Afsluttet date" is blank and I know for a fact that all 1. priorities only have an "aflsuttet date"(enddate), so it should not appear in the graph. 
 
lavmads_1-1674031650070.png

 

Average time =
VAR _dato = MAX(Kalender[Date])
RETURN
AVERAGEX(
    CALCULATETABLE(
        Data,
        ALL(Kalender),
        Data[Registreret dato]<_dato && (Data[Afsluttet dato] > _dato || ISBLANK(Data[Afsluttet dato]))
    ),
    DATEDIFF(Data[Registreret dato], _dato, DAY)
)
 
What is wrong with the equation above?
 
Best regards,
Lisa 
2 REPLIES 2
Mahesh0016
Super User
Super User

@Anonymous 

Average time =
VAR _dato =
MAX ( Kalender[Date] )
RETURN
AVERAGEX (
FILTER (
Data,
CALCULATE (
ALL ( Kalender ),
Data[Registreret dato] < _dato
&& OR ( Data[Afsluttet dato] > _dato, ISBLANK ( Data[Afsluttet dato] ) )
)
),
DATEDIFF ( Data[Registreret dato], _dato, DAY )
)

 

@Anonymous If this post helps, please consider accept as solution to help other members find it more quickly and Appreciate your Kudos.

Anonymous
Not applicable

@Mahesh0016 

What is the right setup? Because if I copy past your equation it says something is wrong. 

 

VAR _dato =
MAX ( Kalender[Date] )
RETURN
AVERAGEX(
    FILTER (
    Data,
    CALCULATE(
    ALL (Kalender),
    Data[Registreret dato] < _dato
    && OR ( Data[Afsluttet dato] > _dato, ISBLANK ( Data[Afsluttet dato] ) )
    )
    ),
    DATEDIFF ( Data[Registreret dato], _dato, DAY )
)

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! It's time to submit your entry.

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.