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
soji
Frequent Visitor

Add new column using DAX 1

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.

 

Capture.JPG

Thanks

Soji

3 REPLIES 3
wdx223_Daniel
Super User
Super User

@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] )
    )
amitchandak
Super User
Super User

@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)

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Hi Amit,

 

I tried as you suggested but all lines are filled with last "New Department" Date.

 

Department = //IF('Employee monthwise'[Old Dept]=BLANK(),CALCULATE(FIRSTNONBLANK('Employee monthwise'[Old Dept],TRUE())))
Var OldDep = MAXX(FILTER('Employee monthwise','Employee monthwise'[Emp Id] = EARLIER('Employee monthwise'[Emp Id]) && 'Employee monthwise'[Date]>EARLIER('Employee monthwise'[Date])),FIRSTNONBLANK('Employee monthwise'[Date],'Employee monthwise'[Old Dept]))
Var NewDep = MAXX(FILTER('Employee monthwise','Employee monthwise'[Emp Id] = EARLIER('Employee monthwise'[Emp Id]) && 'Employee monthwise'[Date]<=EARLIER('Employee monthwise'[Date])),FIRSTNONBLANK('Employee monthwise'[Date],'Employee monthwise'[New Dept]))
Return
IF(ISBLANK(NewDep),OldDep,NewDep)

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!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.