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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
Elaina0907
New Member

Need Help! - Custom Column for Repeating Values

Hi all, I'm looking for assistance building a Custom Column. I have an appended report feeding into PowerBI that tracks our annual headcount as of Jan-1 of each year by Associate ID. If an associate is active with us for multiple years, they will return multiple rows, each under its own year and row index. 

 

My question is how can I create a Custom Column to accomplish the following:

IF 'Associate ID' value repeats from one Headcount Year to the next, return "Retained"

IF 'Associate ID' value does NOT repeat from one Headcount Year to the next, return "Terminated"

IF 'Headcount Year' = 2025 (or current year), return "Not Applicable" as retention to the next year cannot be calculated yet.

 

Here is an example of what my table looks like. The Column D in Red is what I am trying to produce.

Table: Annual Headcount

Row/IndexColumn AColumn BColumn CColumn D
1Headcount YearNext Headcount Year

Associate ID

Retained to Next Year?
2202320241001Retained
3202420251001Retained
4202520261001Not Applicable
5202320241002Retained
6202420251002Terminated
7202320211003Terminated

 

Other Notes:

  • I have the table in PowerQuery sorted as shown above. First by Associate ID - Ascending, second by Headcount Year - Ascending. 
  • In Excel I accomplished this by using the following formula: =IF(C3=C2,"Retained",IF(A2=2025,"Not Applicable","Terminated"))

 

Thanks!

3 REPLIES 3
v-yiruan-msft
Community Support
Community Support

Hi @Elaina0907 ,

You can create a calculated column as below to get it, please find the details in the attachment.

Retained to Next Year? = 
VAR _aid = 'Table'[Associate ID]
VAR _hcyear = 'Table'[Headcount Year]
VAR _next =
    CALCULATE (
        MAX ( 'Table'[Associate ID] ),
        FILTER (
            'Table',
            'Table'[Associate ID] = _aid
                && 'Table'[Headcount Year] = _hcyear + 1
        )
    )
RETURN
    IF (
        NOT ( ISBLANK ( _next ) ),
        "Retained",
        IF ( _hcyear IN { 2025, YEAR ( TODAY () ) }, "Not Applicable", "Terminated" )
    )

vyiruanmsft_0-1741744931584.png

Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
ryan_mayu
Super User
Super User

@Elaina0907 

you can try this

Column =
if('Table'[Headcount Year]=year(today()),"Not Applicable", if (not(ISBLANK(maxx(FILTER('Table','Table'[Associate ID]=EARLIER('Table'[Associate ID])&&'Table'[Headcount Year]=EARLIER('Table'[Next Headcount Year])),'Table'[Headcount Year]))),"Retained","Terminated"))
11.PNG
 
pls see the attachment below
 
 




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




amitchandak
Super User
Super User

@Elaina0907 , You try out approch like

 

Customer Retention with Dynamic Segmentation, New/Lost/Retain Customer Count: https://youtu.be/EyL7KMw877Q

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

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!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

Feb2025 NL Carousel

Fabric Community Update - February 2025

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