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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
pmonte
Frequent Visitor

How can I get the previous "non zero" value in power query m?

Let's imagine a simple table:

IndexCityStep
1NYC1
2NYC0
3NYC0
4NYC0
5LA5
6LA0
7NYC7
8NYC0

 

How can I changes zeros in Step to the previous non zero value so to obtain the Goal coloumn?

 

IndexCityStepGoal
1NYC11
2NYC01
3NYC01
4NYC01
5LA55
6LA05
7NYC77
8NYC07

 

I tried using an index coloumn and List.Range but it only works with the first row with zero (imagine processing row number #2, I can get the value in Step on the previous row which is 1, great. For row #3 unfortunately the previous value is 0).

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @pmonte ,

 

As the data sample you provided, I'd suggest you replace 0 with null and then use Fill Down to simply change the zero value to non zero value.
Replace 0 with null.PNGFill down.jpg

The final output is shown below:

fill step.PNG

Best Regards,
Eyelyn Qin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Hi @pmonte ,

 

As the data sample you provided, I'd suggest you replace 0 with null and then use Fill Down to simply change the zero value to non zero value.
Replace 0 with null.PNGFill down.jpg

The final output is shown below:

fill step.PNG

Best Regards,
Eyelyn Qin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

amitchandak
Super User
Super User

@pmonte , Try a new column like

 

new column =
var _ind = maxx(filter(Table, [City] = ealier([City]) && [Step] <>0), [Index])
var _1 = maxx(filter(table, [Index] =_ind ), [Step])
return
if(isblank(_1), [step], _1)

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

Hello @amitchandak and thanks a lot but this in DAX, I'd need to do this in Query M, any ideas?

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.

Top Solution Authors
Top Kudoed Authors