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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
dep
New Member

how to calculate the average in one month when some data start or finish in the previous/next month

dep_0-1740479623268.png

As you can see I change one key parameter in my process in different date and then I keep it for several days. Then I change for some reason. I would like the monthly average, knowing that sometime I start in the previous month ......

Can someone help me to build the proper way to calculate?

Thanks

 

1 ACCEPTED SOLUTION
bhanu_gautam
Super User
Super User

@dep Create a Date Table:
DateTable =
CALENDAR (DATE(2024, 1, 1), DATE(2025, 12, 31))


Add Year and Month Columns to Date Table:

 

DateTable =
ADDCOLUMNS (
DateTable,
"Year", YEAR([Date]),
"Month", MONTH([Date])
)


Calculate Daily Values: Assuming you have a table named Data with columns StartDate, EndDate, and Value:
DailyValues =
ADDCOLUMNS (
GENERATE (
Data,
CALENDAR (Data[StartDate], Data[EndDate])
),
"DailyValue", Data[Value] / (DATEDIFF (Data[StartDate], Data[EndDate], DAY) + 1)
)


Distribute Values Across Days:
DistributedValues =
SUMMARIZE (
DailyValues,
[Date],
"TotalDailyValue", SUM (DailyValues[DailyValue])
)


Aggregate Monthly Values:
DAX
MonthlyValues =
SUMMARIZE (
DistributedValues,
YEAR([Date]), MONTH([Date]),
"TotalMonthlyValue", SUM (DistributedValues[TotalDailyValue])
)


Calculate Monthly Average:
DAX
MonthlyAverage =
ADDCOLUMNS (
MonthlyValues,
"DaysInMonth", DAY (EOMONTH (DATE (MonthlyValues[Year], MonthlyValues[Month], 1), 0)),
"MonthlyAverage", [TotalMonthlyValue] / [DaysInMonth]
)




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






View solution in original post

1 REPLY 1
bhanu_gautam
Super User
Super User

@dep Create a Date Table:
DateTable =
CALENDAR (DATE(2024, 1, 1), DATE(2025, 12, 31))


Add Year and Month Columns to Date Table:

 

DateTable =
ADDCOLUMNS (
DateTable,
"Year", YEAR([Date]),
"Month", MONTH([Date])
)


Calculate Daily Values: Assuming you have a table named Data with columns StartDate, EndDate, and Value:
DailyValues =
ADDCOLUMNS (
GENERATE (
Data,
CALENDAR (Data[StartDate], Data[EndDate])
),
"DailyValue", Data[Value] / (DATEDIFF (Data[StartDate], Data[EndDate], DAY) + 1)
)


Distribute Values Across Days:
DistributedValues =
SUMMARIZE (
DailyValues,
[Date],
"TotalDailyValue", SUM (DailyValues[DailyValue])
)


Aggregate Monthly Values:
DAX
MonthlyValues =
SUMMARIZE (
DistributedValues,
YEAR([Date]), MONTH([Date]),
"TotalMonthlyValue", SUM (DistributedValues[TotalDailyValue])
)


Calculate Monthly Average:
DAX
MonthlyAverage =
ADDCOLUMNS (
MonthlyValues,
"DaysInMonth", DAY (EOMONTH (DATE (MonthlyValues[Year], MonthlyValues[Month], 1), 0)),
"MonthlyAverage", [TotalMonthlyValue] / [DaysInMonth]
)




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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