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

Average days an event is open over the previous 12 months (this is rolling as the year progresses).

Hay everyone, 

I have a request to duplicate a visual the customer creates in excel into a report. 

 

Problem 

The customer would like a line chart with the Average Days an Event is Open on the Y axis and the month on the X axis - the month needs to advance as the year progresses.  (The chart today will show August 2023 to August 2024 next month it will show Sep 2023 - Sep 24) There will also be a secondary line with the metric of days that the Event should be Open (90 days). 

AVE time open.png

Data Model

There are in my mini model 3 tables Audit , Action and Date

Some sample data

Audit 

Audit IDDate Raisednew_projectfunctionAudit Conducted DateCAR Required
5722/05/202410000003222/05/2024Yes
5829/05/202410000004002/05/2024Yes
5904/06/202410000000409/05/2024Yes
6024/06/202410000003211/06/2024Yes
6130/06/202410000003230/06/2024Yes
6217/07/202410000004017/07/2024Yes
6329/07/202410000003229/07/2024Yes
6430/07/202410000003216/06/2024Yes
6512/08/202410000004012/08/2024No

 

Actions

Audit IDAudit Conducted DateCAR Due DateCompletion DateCAR CategoryStandards NameStandards ClausesCAR StatusDays CAR Open
5722/05/202422/08/202425/06/2024MajorISO 90017.5 Documented informationClosed34
5722/05/202422/08/202419/08/2024MajorISO 90017.5 Documented informationClosed89
5722/05/202429/06/202424/06/2024MajorISO 90017.5 Documented informationClosed33
6011/06/202415/09/202408/07/2024SFIISO 90017.5 Documented informationClosed27
6130/06/202401/01/202530/06/2024SFIISO 90019.2 Internal auditClosed0
6217/07/202415/08/202421/08/2024MajorISO 450018.1 Operational planning and controlClosed35
6217/07/202415/08/202421/08/2024MajorISO 450018.1 Operational planning and controlClosed35
5802/05/202403/11/2024 MinorISO 140016.2 Environmental objectives and planning to achieve themOpen113
5909/05/202410/11/2024 MinorISO 140016.2 Environmental objectives and planning to achieve themOpen106
6011/06/202415/09/2024 SFIISO 450018.1 Operational planning and controlOpen73
6329/07/202430/10/2024 MinorISO 90018.2 Requirements for products and servicesOpen25
6416/06/202426/09/2024 MinorISO 140019.1 Monitoring, measurement, analysis, and evaluationOpen68


Date table is your standard date table built in M at a day per year = 365 with all the normal columns you need. 

 

There is One Audit to Many (N ) CARs attached to each audit.  

 

The date table is currently linked to the Audit Completed date but there are inactive relationships to Completion Date and Due Date but not being used in this instance. 

In the full model there are many dimensions for Staff and Projects etc., that the report is using. 

 

I can easily find the average days open for each Audit using AVERAGEX and iterating the total days by the ID

 

Ave days open CAR ID = 
AVERAGEX(
   VALUES( CAR[CAR ID] ),
    [Total Days CAR Open] 
)

 

 
I issue is that the visual is then totaling these by the conducted date and not giving the correct result as a rolling total each month, it is fixing them to the conducted date in the filter context from the date table. 

I think that what I need to do is build a table that takes the start date - then counts a running total of each day until it finishes - and then have these values in the line chart by the date as a moving total as time goes by with the dates for each date from the start date to the end dates.  I have built this in M to see what it looks like and as a virtual table but, I cannot make the leap to get the visual to match the above example.  - the customer manually builds this each month with raw totals and months calculated and then tunred into the graph.   

What the customer has done in Excel is easy as there placing each total value for the CAR in the table each month and producing the graph then changing the totals and the dates each month to make a new chart, but this is not how a semantic model works, this is the last piece of the puzzle and my brain hurts on a Friday sunny afternoon, so I think I am over thinking this and making it complicated! 

Any new thoughts would be a great help as my VAR virtual tables and DAX is getting longer and longer as I think about this problem and do not solve it!  

Any help greatly welcome. 

5 REPLIES 5
Greg_Deckler
Super User
Super User

@DemoFour I think you need something like this: Open Tickets - Microsoft Fabric Community



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler 

This solution is counting the number of tickets in a time frame, what I need to do is average the number of days open on each day (on a rolling basis) so I am not sure it will work the same.

I need to work out the avarage days open on a given day for each event - so can this be used in the last VAR instead of a COUNTXX ? 

Output = 

DemoFour_0-1725032881590.png

 

 

 

 

 

Test = 

VARTmpTickets = ADDCOLUMNS(
    CAR , 
    "Effective Date" , 
    IF(
       ISBLANK( CAR[Completion Date] ),
        TODAY(),
        CAR[Completion Date]
    )
)
VARTmpTable = SELECTCOLUMNS(
    FILTER(
        GENERATE(
           TmpTickets,
            'Calendar'
        ),
        AND(
        [Date] >= CAR[Audit Conducted Date] && [Date] <= [Effective Date],
        NOT( CAR[Audit Conducted Date] = [Effective Date] )
        )
    ),
    CARID", CAR[CAR ID],
    "Date", [Date]
)

VARTmpTable1 = GROUPBY(
   TmpTable,CARID], 
    "Count",COUNTX(CURRENTGROUP(), [Date] )
)
RETURN

COUNTROWS(TmpTable1 )

 

 

 

 

@DemoFour Correct, in your case you would need to modify the measure so that after you work out the effective date you would then need to add a column that calculated the number of days from the date opened to the effective date. You can use simple math to do this ( [effective date] - [opened date] ) * 1. for example. Once you have that, then you would need to do an AVERAGEX across the table for that column.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler  Can you post up an example please as I am not getting a cohent return value

Thanks @Greg_Deckler 
Will give that a go 🙂

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.