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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
kc_
Helper I
Helper I

Rolling Daily Average Resetting at Beginning of Each Month

Hello All 

 

Below is what I am trying to achieve in Power BI:

 

kc__1-1721811100489.png

 

In essence I need to be able to create a daily rolling average which resets at the beginning of each new month....

 

Thanks in advance!

 

 

2 ACCEPTED SOLUTIONS
bhanu_gautam
Super User
Super User

@kc_ ,Create a new calculated column using below measure

 

Rolling Average =
VAR CurrentDate = 'Table (2)'[Date]
VAR CurrentMonth = MONTH(CurrentDate)
VAR CurrentYear = YEAR(CurrentDate)
RETURN
    CALCULATE(
        AVERAGE('Table (2)'[Job Completed per dat]),
        FILTER(
            'Table (2)',
            YEAR('Table (2)'[Date]) = CurrentYear &&
            MONTH('Table (2)'[Date]) = CurrentMonth &&
            'Table (2)'[Date] <= CurrentDate
        )
    )
 
Attaching PBIX with solution

 




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

Proud to be a Super User!




LinkedIn






View solution in original post

Joe_Barry
Super User
Super User

Hi @kc_ 

Are you usinga date table in your model? Then this will help

Avg. Jobs Per Day = 
VAR LastCurrentDate =
    MAX ( 'DIM Date'[Date] )
VAR Period =
    DATESBETWEEN ( 'DIM Date'[Date], EOMONTH(LastCurrentDate, -1) + 1, LastCurrentDate)
VAR TotalJobs =
    CALCULATE (
        SUM(Jobs[Jobs Completed per Day]),
        Period
    )
VAR NumOfDays =
    COUNTROWS(Period)
VAR Result =
    DIVIDE(TotalJobs, NumOfDays)
RETURN
    Result

Joe_Barry_0-1721814006461.png


Joe

 

 




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Learn about the Star Schema, it will solve many issues in Power BI!

Date tables help! Learn more



LinkedIn
Let's connect on LinkedIn


View solution in original post

9 REPLIES 9
Joe_Barry
Super User
Super User

Hi @kc_ 

Are you usinga date table in your model? Then this will help

Avg. Jobs Per Day = 
VAR LastCurrentDate =
    MAX ( 'DIM Date'[Date] )
VAR Period =
    DATESBETWEEN ( 'DIM Date'[Date], EOMONTH(LastCurrentDate, -1) + 1, LastCurrentDate)
VAR TotalJobs =
    CALCULATE (
        SUM(Jobs[Jobs Completed per Day]),
        Period
    )
VAR NumOfDays =
    COUNTROWS(Period)
VAR Result =
    DIVIDE(TotalJobs, NumOfDays)
RETURN
    Result

Joe_Barry_0-1721814006461.png


Joe

 

 




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Learn about the Star Schema, it will solve many issues in Power BI!

Date tables help! Learn more



LinkedIn
Let's connect on LinkedIn


@Joe_Barry hoping you can provide some further assistance...

As mentioned before the DAX you provided works, see table below:

 

kc__0-1721905752682.png

However, for each date is a working day allocated to it (within the data set) and when I incorporate this within the table the following occurs:

kc__1-1721905838573.png

In essence I am looking to achieve something similar to the below:

kc__3-1721905997831.png

 

Are you able to assist....

 

Many thanks

Hi @kc_ 

Please try for no Staurdays or Sundays

Avg. Jobs Per Day No Weekends = 
VAR LastCurrentDate =
    MAX ( 'DIM Date'[Date] )
VAR Period =
    DATESBETWEEN ( 'DIM Date'[Date], EOMONTH(LastCurrentDate, -1) + 1, LastCurrentDate)
VAR WeekdaysPeriod =
    FILTER (
        Period,
        WEEKDAY ( 'DIM Date'[Date], 2 ) < 6
    )
VAR TotalJobs =
    CALCULATE (
        SUM(Jobs[Jobs Completed per Day]),
        WeekdaysPeriod
    )
VAR NumOfDays =
    COUNTROWS(WeekdaysPeriod)
VAR Result =
    DIVIDE(TotalJobs, NumOfDays)
RETURN
    Result

 

Joe_Barry_0-1721917646007.png

 



This one will exclude days where no Jobs happen

Avg. Jobs Per Day - Leave out non worked days= 
VAR LastCurrentDate =
    MAX ( 'DIM Date'[Date] )
VAR Period =
    DATESBETWEEN ( 'DIM Date'[Date], EOMONTH(LastCurrentDate, -1) + 1, LastCurrentDate)
VAR NonZeroJobsPeriod =
    FILTER (
        Period,
        CALCULATE ( SUM ( Jobs[Jobs Completed per Day] ) ) > 0
    )
VAR TotalJobs =
    CALCULATE (
        SUM(Jobs[Jobs Completed per Day]),
        NonZeroJobsPeriod
    )
VAR NumOfDays =
    COUNTROWS(NonZeroJobsPeriod)
VAR Result =
    DIVIDE(TotalJobs, NumOfDays)
RETURN
    Result

Joe_Barry_1-1721917719893.png

Joe

 




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Learn about the Star Schema, it will solve many issues in Power BI!

Date tables help! Learn more



LinkedIn
Let's connect on LinkedIn


Thanks for this @Joe_Barry , however, something is not working for me...perhaps you can send accross your PBIX file instead.

 

Also, it is critical that the working day numbers are shown as opposed to the actual days of the week since this is what the company reports on. 

 

Below is a screenshot of what I am trying to achieve.

 

kc__0-1721986209155.png

 

Thanks for this Joe, yes I do have a Date Table, however...see below:

kc__0-1721827000301.png

 

The average jobs per day on 2.01.2024 needs to be 86 and not 43. I only need an average to be calculated if a job has been completed on any given day. Also for context, jobs are only completed Monday to Friday.

 

The workaround therefore - instead of pointing to the date table, I am pointing to the date completed field of the source data table, in doing so, I am getting the expected figures.

kc__1-1721827509058.png

 

This has worked a treat! Many thanks!!!!

bhanu_gautam
Super User
Super User

@kc_ ,Create a new calculated column using below measure

 

Rolling Average =
VAR CurrentDate = 'Table (2)'[Date]
VAR CurrentMonth = MONTH(CurrentDate)
VAR CurrentYear = YEAR(CurrentDate)
RETURN
    CALCULATE(
        AVERAGE('Table (2)'[Job Completed per dat]),
        FILTER(
            'Table (2)',
            YEAR('Table (2)'[Date]) = CurrentYear &&
            MONTH('Table (2)'[Date]) = CurrentMonth &&
            'Table (2)'[Date] <= CurrentDate
        )
    )
 
Attaching PBIX with solution

 




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

Proud to be a Super User!




LinkedIn






Thank you!

Thank you Bhanu - however, would you mind re-attaching the PBIX file please...

kc__0-1721814208450.png

 

Check table by going to model not visual




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

Proud to be a Super User!




LinkedIn






Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.