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

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes! Register now.

Reply
Anonymous
Not applicable

How can I create a custom column that averages a row if it is in a specific date range?

Let's say I have the below data: 

 

DateTotal
10/25/202114
11/2/202142
12/7/202131
1/16/202251
1/18/202257
4/21/202272
6/21/202243
7/4/202227

 

How can I create a custom column that will average the numbers in a specific date range? 
i.e. create a column with (sudo):

 

if [Date] between 10/01/2021 and 12/31/2021 then AVERAGE(Total) else if [Date] between 1/01/2022 and 7/31/2022 then AVERAGE(Total) 

 

Or something similar to that?

2 REPLIES 2
ichavarria
Solution Specialist
Solution Specialist

You can create a custom column using the following steps:

 

  1. Click on "Add Column" in the "Modeling" tab of the Power BI desktop.
  2. Click on "Custom Column" in the dropdown menu.
  3. In the formula bar, enter the following formula:

    Avg Total =
    IF(
          AND(
                   [Date] >= DATE(
    2021, 10, 1),
                   [Date] <= DATE(2021, 12, 31)
           ),
          AVERAGE(Table1[Total]),
          IF(
                  AND(
                            [Date] >= DATE(
    2022, 1, 1),
                            [Date] <= DATE(2022, 7, 31)
                  ),
                  AVERAGE(Table1[Total]),
                  BLANK()
         )
    )
  4. Replace "Table1" with the name of your table and "Total" with the name of your total column.
  5. Press "Enter" to create the custom column.

This formula checks if the date falls within the range of 10/01/2021 and 12/31/2021, and returns the average of the total column for that date range. If the date falls within the range of 1/01/2022 and 7/31/2022, it returns the average of the total column for that date range. If the date falls outside of those date ranges, it returns a blank value.

 

Best regards, 

Isaac Chavarria 


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

Anonymous
Not applicable

Thank you! This helps a bunch. But the issue that I am getting is that they are still just averaging all of them, despite specifying the date ranges. 

I think it is because it is looking for  [Date] >= DATE(2021101), and since they are all greater than or equal to that, it is just looking at that and averaging every row. 

Any suggestions to stop that?

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

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.

Top Solution Authors
Top Kudoed Authors