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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
JC2022
Helper III
Helper III

Week over week measure

Hi,

I have created this "# Open tickets EOP" measure and it is working and looks like this below:

OpenTasksWoW =
VAR MinDate = MIN ( 'dim_date'[Date] )
VAR MaxDate = MAX ( 'dim_date'[Date] )
VAR Result =
    CALCULATE (
        COUNTROWS ( CurrentRow_tasks ),
        CurrentRow_tasks[taskCreatedDateDK] <= MaxDate,
        OR(
            CurrentRow_tasks[taskClosedDateDK] > MinDate,
            ISBLANK(CurrentRow_tasks[taskClosedDateDK])
        ),
        REMOVEFILTERS ( 'dim_date' )
    )
RETURN
    Result

# Open tickets EOP =
CALCULATE (
    [OpenTasksWoW],
    LASTDATE ( 'dim_date'[Date] )
)

But now I also want to calculate the days the ticket is open week over week. This measure is not working because it shows only a value for the first week a ticket is open.

DaysOpen =
VAR CreatedDate = MAX(CurrentRow_tasks[taskCreatedDateDK])
VAR ClosedDate = MAX(CurrentRow_tasks[taskClosedDateDK])
VAR LastDateInPeriod = LASTDATE('dim_date'[Date])

RETURN
    IF(
        ISBLANK(ClosedDate),
        DATEDIFF(CreatedDate, LastDateInPeriod, DAY),
        IF(
            ClosedDate <= LastDateInPeriod,
            DATEDIFF(CreatedDate, ClosedDate, DAY),
            DATEDIFF(CreatedDate, LastDateInPeriod, DAY)
        )
    )

I want a value for EVERY week a ticket is open. So for every end of period it should calculate the days it is open.
In this example: INCIDENT798633 should have value 11 for Year_Week_Numeric = 202506, value 18 for Year_Week_Numeric = 202507, value 25 for Year_Week_Numeric = 202508, etc.

Screenshot 2025-03-20 113920.png


1 ACCEPTED SOLUTION
tamerj1
Super User
Super User

@JC2022 
Aplogies again for the late response.
I hope the following fulfils your requirement.

tamerj1_0-1743243560371.png

DaysOpen = 
VAR MinDate =
    MIN ( 'dim_date'[Date] )
VAR MaxDate =
    MAX ( 'dim_date'[Date] )
RETURN
    AVERAGEX (
        CALCULATETABLE ( 
            VALUES ( CurrentRow_tasks[taskKey] ),
            CurrentRow_tasks[taskCreatedDateDK] <= MaxDate,
            OR (
                CurrentRow_tasks[BusinessClosingDateDK] > MinDate,
                ISBLANK ( CurrentRow_tasks[BusinessClosingDateDK] )
            ),
            REMOVEFILTERS ( 'dim_date' )
        ),
        CALCULATE (
            VAR CreatedDate =
                MAX ( CurrentRow_tasks[taskCreatedDateDK] )
            VAR ClosedDate =
                COALESCE ( MAX ( CurrentRow_tasks[BusinessClosingDateDK] ), MaxDate )
            RETURN
                DATEDIFF ( CreatedDate, MIN ( ClosedDate, MaxDate ), DAY ),
            CurrentRow_tasks[taskCreatedDateDK] <= MaxDate,
            OR (
                CurrentRow_tasks[BusinessClosingDateDK] > MinDate,
                ISBLANK ( CurrentRow_tasks[BusinessClosingDateDK] )
            ),
            REMOVEFILTERS ( 'dim_date' )
        )
    )

 

View solution in original post

13 REPLIES 13
tamerj1
Super User
Super User

@JC2022 
Aplogies again for the late response.
I hope the following fulfils your requirement.

tamerj1_0-1743243560371.png

DaysOpen = 
VAR MinDate =
    MIN ( 'dim_date'[Date] )
VAR MaxDate =
    MAX ( 'dim_date'[Date] )
RETURN
    AVERAGEX (
        CALCULATETABLE ( 
            VALUES ( CurrentRow_tasks[taskKey] ),
            CurrentRow_tasks[taskCreatedDateDK] <= MaxDate,
            OR (
                CurrentRow_tasks[BusinessClosingDateDK] > MinDate,
                ISBLANK ( CurrentRow_tasks[BusinessClosingDateDK] )
            ),
            REMOVEFILTERS ( 'dim_date' )
        ),
        CALCULATE (
            VAR CreatedDate =
                MAX ( CurrentRow_tasks[taskCreatedDateDK] )
            VAR ClosedDate =
                COALESCE ( MAX ( CurrentRow_tasks[BusinessClosingDateDK] ), MaxDate )
            RETURN
                DATEDIFF ( CreatedDate, MIN ( ClosedDate, MaxDate ), DAY ),
            CurrentRow_tasks[taskCreatedDateDK] <= MaxDate,
            OR (
                CurrentRow_tasks[BusinessClosingDateDK] > MinDate,
                ISBLANK ( CurrentRow_tasks[BusinessClosingDateDK] )
            ),
            REMOVEFILTERS ( 'dim_date' )
        )
    )

 

@tamerj1  Very very close now. As we can see in your screenshot, for week 5 the matrix shows 27.5 (which is the correct value, but that's because there is a visual filter on [# Open Orders EOP] > 0), but it shows 22.69 in the line graph. This is due to the fact it is counting the lines with [# Open Orders EOP] is blank as well, while it should only take the [# Open Orders EOP] > 0 into account. See my screenshot. 
I think I have to change the "MinDate" at the end into "MaxDate" but then it is probably the [OpenTaskWoW] measure who needs to be adjusted so in only shows the >0 values.
Screenshot 2025-03-29 143205.png

Hi @JC2022 

tamerj1_0-1743566898999.png

DaysOpen = 
VAR MinDate =
    MIN ( 'dim_date'[Date] )
VAR MaxDate =
    MAX ( 'dim_date'[Date] )
RETURN
    AVERAGEX (
        FILTER ( 
            CALCULATETABLE ( 
                VALUES ( CurrentRow_tasks[taskKey] ),
                CurrentRow_tasks[taskCreatedDateDK] <= MaxDate,
                OR (
                    CurrentRow_tasks[BusinessClosingDateDK] > MinDate,
                    ISBLANK ( CurrentRow_tasks[BusinessClosingDateDK] )
                ),
                REMOVEFILTERS ( 'dim_date' )
            ),
            [# Open Orders EOP] > 0
        ),
        CALCULATE (
            VAR CreatedDate =
                MAX ( CurrentRow_tasks[taskCreatedDateDK] )
            VAR ClosedDate =
                COALESCE ( MAX ( CurrentRow_tasks[BusinessClosingDateDK] ), MaxDate )
            RETURN
                DATEDIFF ( CreatedDate, MIN ( ClosedDate, MaxDate ), DAY ),
            CurrentRow_tasks[taskCreatedDateDK] <= MaxDate,
            OR (
                CurrentRow_tasks[BusinessClosingDateDK] > MinDate,
                ISBLANK ( CurrentRow_tasks[BusinessClosingDateDK] )
            ),
            REMOVEFILTERS ( 'dim_date' )
        )
    )
tamerj1
Super User
Super User

Hi @JC2022 

please try

DaysOpen =
VAR MinDate =
MIN ( 'dim_date'[Date] )
VAR MaxDate =
MAX ( 'dim_date'[Date] )
RETURN
CALCULATE (
VAR CreatedDate =
MAX ( CurrentRow_tasks[taskCreatedDateDK] )
VAR ClosedDate =
COALESCE ( MAX ( CurrentRow_tasks[taskClosedDateDK] ), MaxDate )
RETURN
DATEDIFF ( CreatedDate, MIN ( ClosedDate, MaxDate ), DAY ),
CurrentRow_tasks[taskCreatedDateDK] <= MaxDate,
OR (
CurrentRow_tasks[taskClosedDateDK] > MinDate,
ISBLANK ( CurrentRow_tasks[taskClosedDateDK] )
),
REMOVEFILTERS ( 'dim_date' )
)

Hi @tamerj1,
This works good for the individual tickets, but for a Year_Week_Numeric it looks like it is showing the lowest days open in that Year_Week_Numeric. I would like to see the average per Year_Week_Numeric. 
Thank you for your help! Very much appreciated.

Screenshot 2025-03-22 124829.png

Hi @JC2022 

sorry for the late response 

DaysOpen =
VAR MinDate =
MIN ( 'dim_date'[Date] )
VAR MaxDate =
MAX ( 'dim_date'[Date] )
RETURN
AVERAGEX (
VALUES ( dim_date[Year_Week_Numeric] ),
CALCULATE (
VAR CreatedDate =
MAX ( CurrentRow_tasks[taskCreatedDateDK] )
VAR ClosedDate =
COALESCE ( MAX ( CurrentRow_tasks[taskClosedDateDK] ), MaxDate )
RETURN
DATEDIFF ( CreatedDate, MIN ( ClosedDate, MaxDate ), DAY ),
CurrentRow_tasks[taskCreatedDateDK] <= MaxDate,
OR (
CurrentRow_tasks[taskClosedDateDK] > MinDate,
ISBLANK ( CurrentRow_tasks[taskClosedDateDK] )
),
REMOVEFILTERS ( 'dim_date' )
)
)

Hi @tamerj1,
I am seeing the exact same result. Still the lowest value for the Year_Week_Numeric (red lines) for DaysOpen.
Screenshot 2025-03-26 090052.png

@JC2022 

My mistake!

DaysOpen =
VAR MinDate =
MIN ( 'dim_date'[Date] )
VAR MaxDate =
MAX ( 'dim_date'[Date] )
RETURN
AVERAGEX (
VALUES ( CurrentRow_tasks[TicketID] ),
CALCULATE (
VAR CreatedDate =
MAX ( CurrentRow_tasks[taskCreatedDateDK] )
VAR ClosedDate =
COALESCE ( MAX ( CurrentRow_tasks[taskClosedDateDK] ), MaxDate )
RETURN
DATEDIFF ( CreatedDate, MIN ( ClosedDate, MaxDate ), DAY ),
CurrentRow_tasks[taskCreatedDateDK] <= MaxDate,
OR (
CurrentRow_tasks[taskClosedDateDK] > MinDate,
ISBLANK ( CurrentRow_tasks[taskClosedDateDK] )
),
REMOVEFILTERS ( 'dim_date' )
)
)

@tamerj1  it is still not working, but I have sent you a message.

d_m_LNK
Resolver II
Resolver II

For your LastDateInPeriod Variable, I'm curious what happens if you change it to MAX('dim_date'[Date) instead of LastDate.  It seems like it's only evaluating the max within that week context instead of the whole calendar table.  

@d_m_LNK I tried but it doesn't change anything. Again it shows missing values.

On your variables for CreatedDate and ClosedDate, Change those to SelectedValue() instead of the MAX function as I am guessing you want to get the created an closed dates for those specific tickets and not the MAX created date in that column.

No, this is not solving the problem. Thank you for trying to help. Is anyone else having the solution?

Helpful resources

Announcements
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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