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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

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
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

AugPowerBI_Carousel

Power BI Monthly Update - August 2024

Check out the August 2024 Power BI update to learn about new features.

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

Sept NL Carousel

Fabric Community Update - September 2024

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