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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
mordy111
Frequent Visitor

Help with formula to maintain months when calculating average

Hoping someone can help me with this basic formula question. I'm trying to calculate the average monthly visits per physician using this formula. This works fine when the visual is filtered by month, however, when bringing the filter out to include multiple months the average obviously is no longer accurate. I do have a table for month groups and was wondering if there is some way to add that filter into the average calculation so that no matter how large the visual is, it will always show me an average based on monthly buckets. 

 

Here is my current code:

 

average visits per RENDERING_PROVIDER =
AVERAGEX(
    KEEPFILTERS(VALUES('Providers'[RENDERING_PROVIDER])),
    CALCULATE(SUM('DBAPPOINTMENT'[COUNTAPPOINTMENT]))
)
2 ACCEPTED SOLUTIONS

Try this...

 

AVERAGEX(
	GROUPBY(
		DateTable,
		DateTable[Year],
		DateTable[Month],
		"Visits",
		AVERAGEX(
			CURRENTGROUP(),
			[Total Visits]
		)
	),
	[Visits]
)

 

I'm assuming that you have fields for year and month in your date table.  And that there is a measure called "Total Visits" that calculates that (if not just replace with SUM([field for visits])

View solution in original post

amitchandak
Super User
Super User

@mordy111 , I think you will need a month year column. Try a measure like

 

average visits per RENDERING_PROVIDER =
AVERAGEX(
VALUES('Providers'[Month Year]),
CALCULATE(SUM('DBAPPOINTMENT'[COUNTAPPOINTMENT]))
)

 

or

 

average visits per RENDERING_PROVIDER =
AVERAGEX(
Summarize('Providers'[RENDERING_PROVIDER],'Providers'[Month Year], "_1"
CALCULATE(SUM('DBAPPOINTMENT'[COUNTAPPOINTMENT]))
), divide(sum([_1]), count([RENDERING_PROVIDER])))

View solution in original post

5 REPLIES 5
v-robertq-msft
Community Support
Community Support

Hi, @mordy111 

According to your description, you want to show the value of the measure which can be grouped by month, I suggest you to use the Matrix chart in Power BI:

You can create a Matrix chart then place the [Month] field in Row, then no matter what the selection of Month Slicer will be, it will always show the value group by month, like this:

v-robertq-msft_0-1609752950942.png

 

More info about creating Matrix in Power BI

 

If this result is not what you want, you can post some sample data(without sensitive data) and your expected result.

How to Get Your Question Answered Quickly 

 

Best Regards,

Community Support Team _Robert Qin

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

amitchandak
Super User
Super User

@mordy111 , I think you will need a month year column. Try a measure like

 

average visits per RENDERING_PROVIDER =
AVERAGEX(
VALUES('Providers'[Month Year]),
CALCULATE(SUM('DBAPPOINTMENT'[COUNTAPPOINTMENT]))
)

 

or

 

average visits per RENDERING_PROVIDER =
AVERAGEX(
Summarize('Providers'[RENDERING_PROVIDER],'Providers'[Month Year], "_1"
CALCULATE(SUM('DBAPPOINTMENT'[COUNTAPPOINTMENT]))
), divide(sum([_1]), count([RENDERING_PROVIDER])))

mordy111
Frequent Visitor

Using it as a KPI numerical field. So I guess if I select a few months I'm really looking for the average of the average monthly number for the period selected.

 

(I do also use in a graph with time on axis and it works fine there)

 

 

Try this...

 

AVERAGEX(
	GROUPBY(
		DateTable,
		DateTable[Year],
		DateTable[Month],
		"Visits",
		AVERAGEX(
			CURRENTGROUP(),
			[Total Visits]
		)
	),
	[Visits]
)

 

I'm assuming that you have fields for year and month in your date table.  And that there is a measure called "Total Visits" that calculates that (if not just replace with SUM([field for visits])

littlemojopuppy
Community Champion
Community Champion

I'm wondering if a simple AVERAGE() might suffice.  Depending on how you're going to use this measure, if it's in a matrix or graph with time on the axis, filter context would limit the average to only include those visits in a month in the average calculation...

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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