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!The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more
Hi
I have a table in power BI as mentioned below in yellow highlighted columns and i would like to add a new column using DAX as shown in blue color . Can you please help.
Thanks
Soji
@soji try this code
=
VAR _ChangeLineAfter =
TOPN (
1,
FILTER (
Table,
Table[Employee Name] = EARLIER ( Table[Employee Name] )
&& Table[Month & Year] > EARLIER ( Table[Month & Year] )
&& Table[Department Change] = "YES"
),
Table[Month & Year], ASC
)
VAR _ChangeLineBefore =
TOPN (
1,
FILTER (
Table,
Table[Employee Name] = EARLIER ( Table[Employee Name] )
&& Table[Month & Year] <= EARLIER ( Table[Month & Year] )
&& Table[Department Change] = "YES"
),
Table[Month & Year]
)
RETURN
COALESCE (
MAXX ( _ChangeLineBefore, Table[New Department] ),
MAXX ( _ChangeLineAfter, Table[Old Department] )
)
@soji , Create a new date column
date = "01-" & [Month & Year]
Try a new column like
new column =
var _1 = maxx(filter(Table, Employee =earlier([employee]) && [Date] >earlier(Employee])),firstnonblank(Table[Date],[Old Department]))
var _2 = maxx(filter(Table, Employee =earlier([employee]) && [Date] <=earlier(Employee])),lastnonblank(Table[Date],[New Department]))
return
if(isblank(_2),_1,_2)
Hi Amit,
I tried as you suggested but all lines are filled with last "New Department" Date.
The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!
| User | Count |
|---|---|
| 19 | |
| 13 | |
| 9 | |
| 4 | |
| 4 |
| User | Count |
|---|---|
| 30 | |
| 26 | |
| 17 | |
| 11 | |
| 10 |