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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
jonnyA
Responsive Resident
Responsive Resident

Quick measure to find the average divided by Date of Service?

I have a report that I am working on that has the following ...

  • Shift Name
  • Total # of Patients Per Shift

My report has DOS, so I can select dates of Service, Jan 2021 through July 2021, but I do not know how to create an averaged measure that would show me the average for those months selected?

 

For example, If I were to click on Dates of Servie Jan 2021 through July 2021 then how could i calculate an average for that tiome period?

1 ACCEPTED SOLUTION
v-xiaotang
Community Support
Community Support

Hi @jonnyA 

factly, in your case, the highly recommended thing is to create an independent date table. 

because not having your sample file, so I create one. you can try this.

-

1. create date table, and put it in filter

calendar = CALENDAR(DATE(2021,1,1),DATE(2021,10,1))

2. create the measure, the measure returns average of your selected months

average =
VAR _selectedDate1 =
    CALCULATE ( MIN ( 'calendar'[Date] ), ALLSELECTED ( 'calendar' ) )
VAR _selectedDate2 =
    CALCULATE ( MAX ( 'calendar'[Date] ), ALLSELECTED ( 'calendar' ) )
VAR _sum =
    CALCULATE (
        SUM ( 'Table'[Total # of Patients Per Shift] ),
        FILTER (
            'Table',
            'Table'[Date] <= _selectedDate2
                && 'Table'[Date] >= _selectedDate1
        )
    )
VAR _months =
    DATEDIFF ( _selectedDate1, _selectedDate2, MONTH )
RETURN
    DIVIDE ( _sum, _months )

result

vxiaotang_0-1629954800616.png

if you need more help, please @ me.

 

 

Best Regards,

Community Support Team _Tang

If this post helps, please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
v-xiaotang
Community Support
Community Support

Hi @jonnyA 

factly, in your case, the highly recommended thing is to create an independent date table. 

because not having your sample file, so I create one. you can try this.

-

1. create date table, and put it in filter

calendar = CALENDAR(DATE(2021,1,1),DATE(2021,10,1))

2. create the measure, the measure returns average of your selected months

average =
VAR _selectedDate1 =
    CALCULATE ( MIN ( 'calendar'[Date] ), ALLSELECTED ( 'calendar' ) )
VAR _selectedDate2 =
    CALCULATE ( MAX ( 'calendar'[Date] ), ALLSELECTED ( 'calendar' ) )
VAR _sum =
    CALCULATE (
        SUM ( 'Table'[Total # of Patients Per Shift] ),
        FILTER (
            'Table',
            'Table'[Date] <= _selectedDate2
                && 'Table'[Date] >= _selectedDate1
        )
    )
VAR _months =
    DATEDIFF ( _selectedDate1, _selectedDate2, MONTH )
RETURN
    DIVIDE ( _sum, _months )

result

vxiaotang_0-1629954800616.png

if you need more help, please @ me.

 

 

Best Regards,

Community Support Team _Tang

If this post helps, please consider Accept it as the solution to help the other members find it more quickly.

amitchandak
Super User
Super User

@jonnyA , You need to create measure like

 

sumx(values(Table[Month Year]), calculate(sum(Table[Total # of Patients Per Shift])))

 

 

if needed create new column

Month Year = format([Date], "mmm-yyyy")

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.