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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
Sonya_Zam
Frequent Visitor

Average ED Attendance Calculation for a specific selected month over the last three years

Hi all,

 

I'm trying to figure out how to calculate  the average of ED attendances resulting from injury for a specific selected month over the last three years. In the Emergency Department dataset, there is a variable called "injury" which is a sum variable that includes values of 0 and 1. A value of 1 indicates that the ED attendance was due to an injury.  

 

The Emergency Department dataset (presentation_date) has a relationship with the Date (Date) dimension table, which also include month, year, and week.

 

To clarify, when I select the year 2022 and the month of December, I am hoping to obtain the average ED attendance resulting from injury for that specific month over the last three years. For example, the average ED attendances for the month of December would be 200 over the last three years.

 

Could you please help me out with this? What's the DAX formula that I can use to get this calculation done?

3 REPLIES 3
Sonya_Zam
Frequent Visitor

Many thanks for your reply.

Yes- my table look like the above. The date_attedance in the Emergency Department table has a relationship with the date in the date dimension table.

 

I want to have a slicer that includes the month and year. For example, if I select Feb 2022, I should get the average of the injury attendances of the past three years for the month chosen which is the average of the sum of the month Feb 2022, Feb 2021 and Feb 2020 injury attendance.

 

So let's say injury attendance for Feb 2022 is 10, for Feb 2021 is 15 and for Feb 2020 is 7. So if we select Feb 2022 (from the slicer from the date dimension table), the average for that month for the past three years will be (10+15+7)/3 =10.6 injury attendances.

FreemanZ
Super User
Super User

hi @Sonya_Zam 

not sure if fully i get you, supposing you have a table like this:

FreemanZ_0-1677422740972.png

 

1) try to add slicer visual with the only column from a calculated table like:

Slicer = 
SELECTCOLUMNS(
    {202211, 202212},
    "YYYYMM", [Value]
)

2) plot a measure with such code:

3YAvg = 
VAR _ym = SELECTEDVALUE(Slicer[YYYYMM])
RETURN
DIVIDE(
    CALCULATE(
        SUM(TableName[Injury]),
        VALUE(FORMAT(TableName[Date], "YYYYMM")) IN {_ym, _ym-100, _ym-200}
    ),
    3
)

 

it worked like:

FreemanZ_1-1677422869825.png

FreemanZ_2-1677422889619.png

 

 

Please see my reply in the above. As the current dax forumula don't calculate what I am after. 

Many thanks in adavnce

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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