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

Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM. Register now.

Reply
MiloT
Frequent Visitor

Help with tenure format - average overview

Dear community!

 

I have a small problem, I exported data about users and the deafult export is as below...
I'm trying to calculate the average tenure for the user list, unfortunately PowerBi isn't recognizing this format as duration and defaults to Text. I've tried changing the format by transforming the data but keep getting an error : 

Expression.Error: We couldn't parse the Duration literal.
Details:
1 year, 4 months and 25 days


Screen Shot 2022-03-29 at 1.24.03 PM.png

I'd appreciate any feedback on how to easily get the average tenure for my user list! 

1 ACCEPTED SOLUTION
tamerj1
Super User
Super User

Hi @MiloT 
Here is a sample file with the solution https://www.dropbox.com/t/iulSDAx1AvxBTEyo

> New column :

Number of Days = 
VAR YearLocation = 
    FIND ( "year", 'Duration'[Duration], 1 , 0 )
VAR MonthLocation = 
    FIND ( "month", 'Duration'[Duration], 1 , 0 )
VAR DayLocation = 
    FIND ( "day", 'Duration'[Duration], 1 , 0 )
VAR NumberOfYears =
    IF ( 
        YearLocation <> 0,
        VALUE ( LEFT ( 'Duration'[Duration], 2 ) )
    )
VAR NumberOfMonths =
    IF (
        MonthLocation <> 0,
        IF (
            YearLocation = 0,
            VALUE ( LEFT ( 'Duration'[Duration], 2 ) ),
            IF (
                DayLocation <> 0,
                VALUE ( MID ( 'Duration'[Duration], MonthLocation - 3, 2 ) )
            )
        )
    )
VAR NumberOfDays =
    IF (
        DayLocation <> 0,
        IF (
            YearLocation = 0 && MonthLocation = 0,
            VALUE ( LEFT ( 'Duration'[Duration], 2 ) ),
            VALUE ( MID ( 'Duration'[Duration], DayLocation - 3, 2 ) )
        )
    )
RETURN 
    NumberOfYears * 365 + NumberOfMonths * 30 + NumberOfDays

View solution in original post

2 REPLIES 2
MiloT
Frequent Visitor

This is amazing, thank you so much Tamerj1 - I really appreciate the help, you are a star!

tamerj1
Super User
Super User

Hi @MiloT 
Here is a sample file with the solution https://www.dropbox.com/t/iulSDAx1AvxBTEyo

> New column :

Number of Days = 
VAR YearLocation = 
    FIND ( "year", 'Duration'[Duration], 1 , 0 )
VAR MonthLocation = 
    FIND ( "month", 'Duration'[Duration], 1 , 0 )
VAR DayLocation = 
    FIND ( "day", 'Duration'[Duration], 1 , 0 )
VAR NumberOfYears =
    IF ( 
        YearLocation <> 0,
        VALUE ( LEFT ( 'Duration'[Duration], 2 ) )
    )
VAR NumberOfMonths =
    IF (
        MonthLocation <> 0,
        IF (
            YearLocation = 0,
            VALUE ( LEFT ( 'Duration'[Duration], 2 ) ),
            IF (
                DayLocation <> 0,
                VALUE ( MID ( 'Duration'[Duration], MonthLocation - 3, 2 ) )
            )
        )
    )
VAR NumberOfDays =
    IF (
        DayLocation <> 0,
        IF (
            YearLocation = 0 && MonthLocation = 0,
            VALUE ( LEFT ( 'Duration'[Duration], 2 ) ),
            VALUE ( MID ( 'Duration'[Duration], DayLocation - 3, 2 ) )
        )
    )
RETURN 
    NumberOfYears * 365 + NumberOfMonths * 30 + NumberOfDays

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

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

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 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