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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
mikekim123
Frequent Visitor

A flag to track change in a column to get employee HC changes

Hi Team,

I have an employee HC table and i need to provide analysis for HC added and HC reduced per month.

To achieve this i am trying to create a flag that will keep track of changes by comparing this month and previous month but so far not getting the desired output. The table is having a format as shown below.

mikekim123_0-1681318969322.png
I want to produce columns "Change Flag" and HC Status


Is it possible to create the same using powerquery or dax?

I was able to get the first occurence of an entry using first occurence flag mentioned in below post : https://community.powerbi.com/t5/Power-Query/Flag-first-occurrence-item-in-Power-Query/td-p/2544782
but it doesnt work for repetative change for eg: Emp x got transferred from AEG to ASP then back to AEG, in this case the flag is returning 0 as it is not the first occurence.


1 REPLY 1
AlienSx
Super User
Super User

Hello, @mikekim123 assuming that you have a table "Table1" of Employee Name, Period and Subsidiary in Excel (and btw sorting step is important!) 

let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    types = Table.TransformColumnTypes(Source,{{"Period", type date}}),
    sorting = Table.Sort(types,{{"Employee Name", Order.Ascending}, {"Period", Order.Ascending}}),
    groups = 
        Table.Group(
            sorting, {"Employee Name", "Subsidiary"}, 
            {{"all", each Table.Sort(_, {"Period", Order.Ascending}), type table [Employee Name = text, Period=nullable date, Subsidiary=text]}}, 
            GroupKind.Local, 
            (s, c) => Number.From((s[Subsidiary] <> c[Subsidiary]) or (s[Employee Name] <> c[Employee Name]))
        ),
    fx_add_columns = (t as table) as table =>
        Table.FromColumns(
            Table.ToColumns(t) & {{1} , {"HC ADDED TO " & t[Subsidiary]{0}}},
            Table.ColumnNames(t) & {"Change Flag"} & {"HC Status"}
        ),
    almost_there = Table.Combine(Table.TransformColumns(groups, {"all", fx_add_columns})[all]),
    z = 
        Table.TransformColumns(
            almost_there, 
            {{"Change Flag", each Replacer.ReplaceValue(_, null, 0)},
            {"HC Status", each Replacer.ReplaceValue(_, null, "")}}
        )

in
    z

 

 

 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 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.