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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
TheeWoko
New Member

Average of range of dates.

I have a column of dates as text. some are ranges. I want to use the average of the ranges as the final date while keeping the non-ranges before converting all to int so I can do some more work on them. I've tried extracting the ranges as text so I can subsequently average them, didn't work.

TheeWoko_0-1754725251989.png

 

 

1 ACCEPTED SOLUTION
MohamedFowzan1
Responsive Resident
Responsive Resident

Hi @TheeWoko 

Use the below logic to checksif the text contains a hyphen ("-"), splits the range, calculates the average, and returns it as a number.

If no range, it converts the text directly to number.
New custom column with MCode:

// Custom column logic
let
    DateText = [Date], // Replace 'Date' with your actual column name
    HasRange = Text.Contains(DateText, "-"),
    Result =
        if HasRange then
            let
                Parts = Text.Split(DateText, "-"),
                StartNum = Number.FromText(Parts{0}),
                EndNum = Number.FromText(Parts{1}),
                AvgNum = Number.Round((StartNum + EndNum) / 2, 0)
            in
                AvgNum
        else
            Number.FromText(DateText)
in
    Result

View solution in original post

2 REPLIES 2
MohamedFowzan1
Responsive Resident
Responsive Resident

Hi @TheeWoko 

Use the below logic to checksif the text contains a hyphen ("-"), splits the range, calculates the average, and returns it as a number.

If no range, it converts the text directly to number.
New custom column with MCode:

// Custom column logic
let
    DateText = [Date], // Replace 'Date' with your actual column name
    HasRange = Text.Contains(DateText, "-"),
    Result =
        if HasRange then
            let
                Parts = Text.Split(DateText, "-"),
                StartNum = Number.FromText(Parts{0}),
                EndNum = Number.FromText(Parts{1}),
                AvgNum = Number.Round((StartNum + EndNum) / 2, 0)
            in
                AvgNum
        else
            Number.FromText(DateText)
in
    Result
MattAllington
Community Champion
Community Champion

I can only see ranges. It's hard to give solid guidance unless the sample data is typical. I would be doing something like

load the data into Power Query

split column on the delimiter "-" to create 2 columns 

convert to integer

add a new column to do your average calculation (add custom column, then do the calc to get the average)



* Matt is an 8 times Microsoft MVP (Power BI) and author of the Power BI Book Supercharge Power BI.
I will not give you bad advice, even if you unknowingly ask for it.

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors