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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Anonymous
Not applicable

how to use the if loop to add new column (power M)

Dear friend,

 

How to use the if loop to add a new column like this info.

I want a new column looking for other columns but in the row is not null if null will look for a higher row looping like below but i don't want write long till -60

 

if [Column5]<> null
then [Column5]
else if #"Replaced Value" [Column5]{[Index]-1} <> null
then #"Replaced Value" [Column5]{[Index]-1}
else if #"Replaced Value" [Column5]{[Index]-2} <> null
then #"Replaced Value" [Column5]{[Index]-2}
else if #"Replaced Value" [Column5]{[Index]-3} <> null
then #"Replaced Value" [Column5]{[Index]-3}

 

Thank you

2 REPLIES 2
amitchandak
Super User
Super User

@Anonymous , You can use List.Select or each

 

new column example

let
_ind = [Index]
_Table = Table.Select(#"Replaced Value" , each [Index] <_ind)
_list = List.Select(#"Replaced Value"[Column5] , each _ <> null)
_value = if List.IsEmpty(_list) then _list{0} else null
in
_value

 

List.Reverse can be used in case the it in revrese order

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
Anonymous
Not applicable

Dear @amitchandak 

thank you may i ask for how to use this code i still don't understand let and in

tep_0-1667793635830.png

 

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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