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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
mpompilio
Frequent Visitor

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

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
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.