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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
738o51
Helper II
Helper II

Rolling Average sensitive to weekday

Hi everyone,

 

I am working on building a visual that should show an average daily census (ADC) for a period determined by a date slicer, by each day of week. I also want to add a line that shows a 12 month rolling average from which to compare the ADC for the selected time period.

 

I've tried two formulas and neither have accomlished what I want.

 

Formula A: 

The good: this formula is responsive to the weekday axis

The bad: this formula doesn't work when my selected time period is less than 12 months. Then, it defaults to equal the average for the time period selected.

Rolling Average 0600 12 ADC = 
Divide(
    CALCULATE(
        sum(Datebedfacil[0600]),
        ALL(Datebedfacil[0600]),
        DATESINPERIOD(
            Datebedfacil[Date],
            LASTDATE(Datebedfacil[Date]),
            -12,MONTH
        )
    )
    ,
    CALCULATE(
        DISTINCTCOUNT(Datebedfacil[Date]),
        ALL(Datebedfacil[Date]),
        DATESINPERIOD(
            Datebedfacil[Date],
            LASTDATE(Datebedfacil[Date]),
            -12,MONTH
        )
    )
)

 

Formula B:

The good: this works to show a 12 month average regarless of the time set by the slicer

The bad: this isn't responsive to the weekday axis.

Rolling Average 0600 12 ADC = 
Divide(
    CALCULATE(
        sum(Datebedfacil[0600]),
        ALL(Datebedfacil),
        DATESINPERIOD(
            Datebedfacil[Date],
            LASTDATE(Datebedfacil[Date]),
            -12,MONTH
        )
    )
    ,
    CALCULATE(
        DISTINCTCOUNT(Datebedfacil[Date]),
        ALL(Datebedfacil),
        DATESINPERIOD(
            Datebedfacil[Date],
            LASTDATE(Datebedfacil[Date]),
            -12,MONTH
        )
    )
)

 

The weekdays come from my date table. There is an active relationship between the Date[Date] column and the Datebedfacil[Date] column. 

Can anyone help? Unforunately I cannot share a .pbix due to private health information. Thanks in advance!

3 REPLIES 3
sturlaws
Resident Rockstar
Resident Rockstar

Hi @738o51,

 

perhaps you could create a relevant mockup report to share?

 

Not sure if I understand your requirements correctly, but assuming you have a calendar/date-dimension you can try the following code:

Measure =
VAR _maxSlicerDate =
    ( MAX ( dim_date[Date] ) )
VAR _dayOfWeek =
    MAX ( dim_date[WeekdayNum] )
RETURN
    CALCULATE (
        AVERAGE ( 'Table'[MockupValue] );
        FILTER (
            ALL ( dim_date );
            dim_date[WeekdayNum] = _dayOfWeek
                && dim_date[Date] >= _maxSlicerDate - 365
                && dim_date[Date] <= _maxSlicerDate
        )
    )


I have created a simple mockup report to demonstrate

 

Cheers,
Sturla

If this post helps, then please consider Accepting it as the solution. Kudos are nice too.

Thanks for your help! Unforunately this didn't work.

 

Maybe this will help explain the problem:

ADC is my variable shown in columns. It equals the average daily census and is broken down by day of week.

 

Let's assume my date slicer is set to show 6 months.

 

If I use formula A, my chart looks like this:

Capture 2.JPG

 

If I use formula B, my chart looks like this:

 

 

Thanks again!

Capture.JPG

 

Sorry it looks like my second photo didn't load. Here is Formula B^

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Power BI Monthly Update - May 2024

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

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.