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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Company Durations

I have a table with a list of companies and their start and end dates:

1.PNG

 

I am trying to figure out the best way to create a calculated column that will show their durations in 1 year intervals. So I'm looking for categories of:

  • 1-2 Years
  • 2-3 Years
  • 3-4 Years

With the final category being 10+ Years. Also, my data is dynamic so everyday the current date is updated. So for instance once a company has been with us for over 3 years, their duration is updated from 2-3 to 3-4. I'm sure it's some kind of switch statement but I haven't quite been able to figure out how to get it right. Thanks!

 

1 ACCEPTED SOLUTION
Zubair_Muhammad
Community Champion
Community Champion

Hi @Anonymous

 

You can do it with the help of a small PARAMETER TABLE... such as below

Copy paste the Table below to your Power BI Desktop and name it "PARAMETERS"

 

CategoryStartEnd
0-1 years01
1-2 years12
2-3 years23
3-4 years34
4-10 years410
10+ years101000

 

Now assuming your TableName is Table1,, you can add this calculated column to your Table 1 to get the categories

 

Category =
VAR No_of_Years =
    DATEDIFF ( Table1[Start], Table1[End], DAY ) / 365
RETURN
    CALCULATE (
        FIRSTNONBLANK ( Parameters[Category], 1 ),
        FILTER (
            Parameters,
            No_of_Years >= Parameters[Start]
                && No_of_Years < Parameters[End]
        )
    )

 


Regards
Zubair

Please try my custom visuals

View solution in original post

1 REPLY 1
Zubair_Muhammad
Community Champion
Community Champion

Hi @Anonymous

 

You can do it with the help of a small PARAMETER TABLE... such as below

Copy paste the Table below to your Power BI Desktop and name it "PARAMETERS"

 

CategoryStartEnd
0-1 years01
1-2 years12
2-3 years23
3-4 years34
4-10 years410
10+ years101000

 

Now assuming your TableName is Table1,, you can add this calculated column to your Table 1 to get the categories

 

Category =
VAR No_of_Years =
    DATEDIFF ( Table1[Start], Table1[End], DAY ) / 365
RETURN
    CALCULATE (
        FIRSTNONBLANK ( Parameters[Category], 1 ),
        FILTER (
            Parameters,
            No_of_Years >= Parameters[Start]
                && No_of_Years < Parameters[End]
        )
    )

 


Regards
Zubair

Please try my custom visuals

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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