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
Anonymous
Not applicable

Average per row, reseting on each month

Hello!

First Post.

 

I have data of my country's position on a ranking list.

I need to determine the average of that position for each month separately.

Currently im using:

 

Promedio = CALCULATE(
            AVERAGE(PowerBI[Posición]);
                        FILTER(PowerBI;
                       PowerBI[Fecha].[Month]<=EARLIER(PowerBI[Fecha].[Month])
                      && PowerBI[Fecha].[Day]<=EARLIER(PowerBI[Fecha].[Day]))
)

 

But the averages are wrongly calculated.
I also noticed that on the first day of the month if position is 50 the average shows 55.5 which means its carrying values from the previous months.

 

Question.jpg

 

Please help me fix my formula. Thanks in advance.

1 ACCEPTED SOLUTION
v-zhenbw-msft
Community Support
Community Support

Hi @Anonymous ,

 

We can use the following steps to meet your requirement.

 

1. Create two calculate columns, one is year, another is month.

 

Month = MONTH('Table'[Date])      

year = YEAR('Table'[Date])

 

A 1.jpg

 

2. Then we can create a measure,

 

Each month AVG = 
var current_month = MAX('Table'[Month])
var Total_value = CALCULATE(SUM('Table'[value]))
var Month_day = CALCULATE(DISTINCTCOUNT('Table'[Date]),FILTER('Table','Table'[Month] = current_month))
return
DIVIDE(Total_value,Month_day)

 

The result like this,

 

A 2.jpg

 

3. Or we can create a calculate column,

 

AVG column = 
var total_month = CALCULATE(DISTINCTCOUNT('Table'[Date]),FILTER(ALLSELECTED('Table'),'Table'[Month]=EARLIER('Table'[Month])&& 'Table'[year]=EARLIER('Table'[year])))
var current_month = CALCULATE(SUM('Table'[value]),FILTER(ALLSELECTED('Table'),'Table'[Month]=EARLIER('Table'[Month]) && 'Table'[year]=EARLIER('Table'[year])))
return
DIVIDE(current_month,total_month)

 

The result like this,

 

A 3.jpg

 

If it doesn’t meet your requirement, could you please show the exact expected result based on the table that you have shared?

BTW, pbix as attached.

 

Best regards,

 

Community Support Team _ zhenbw

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

View solution in original post

3 REPLIES 3
v-zhenbw-msft
Community Support
Community Support

Hi @Anonymous ,

 

We can use the following steps to meet your requirement.

 

1. Create two calculate columns, one is year, another is month.

 

Month = MONTH('Table'[Date])      

year = YEAR('Table'[Date])

 

A 1.jpg

 

2. Then we can create a measure,

 

Each month AVG = 
var current_month = MAX('Table'[Month])
var Total_value = CALCULATE(SUM('Table'[value]))
var Month_day = CALCULATE(DISTINCTCOUNT('Table'[Date]),FILTER('Table','Table'[Month] = current_month))
return
DIVIDE(Total_value,Month_day)

 

The result like this,

 

A 2.jpg

 

3. Or we can create a calculate column,

 

AVG column = 
var total_month = CALCULATE(DISTINCTCOUNT('Table'[Date]),FILTER(ALLSELECTED('Table'),'Table'[Month]=EARLIER('Table'[Month])&& 'Table'[year]=EARLIER('Table'[year])))
var current_month = CALCULATE(SUM('Table'[value]),FILTER(ALLSELECTED('Table'),'Table'[Month]=EARLIER('Table'[Month]) && 'Table'[year]=EARLIER('Table'[year])))
return
DIVIDE(current_month,total_month)

 

The result like this,

 

A 3.jpg

 

If it doesn’t meet your requirement, could you please show the exact expected result based on the table that you have shared?

BTW, pbix as attached.

 

Best regards,

 

Community Support Team _ zhenbw

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

Anonymous
Not applicable

The second Solution/Formula worked perfectly! 

Thank you for you quick response.

Anonymous
Not applicable

I would actually just need the average of the whole month I dont really need it to be daily. So that i can Display this table containing ech month:

 

q2.jpg

 

Any idea would be appreciated! Thanks.

Helpful resources

Announcements
July 2024 Power BI Update

Power BI Monthly Update - July 2024

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

July Newsletter

Fabric Community Update - July 2024

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