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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Mpcz
Frequent Visitor

Power Query- how to replace null with previous row value

Hi All,

I would like to ask for your help with understanding how to replace a null value with value of the previous row.

 

What i would need to happen based on the below example is to fill up row with index number 18 of "Wykonanie" column with the the value +9 of row with index 17. So the result for row 18 would equal to 76,939+9=85,939. Then for 19th 85,939+9 and so on till it hits the row without null. Please ingore row #12 it will be filled up.

Mpcz_0-1661175438065.png

Thank you in advance 🙂

1 ACCEPTED SOLUTION

Hi @Mpcz ,

 

I suggest you to try this code.

if [Index]>17 and [Wykonanie] = null then 
let _Wykonanie = 
Table.Max(
Table.SelectRows(#"Changed Type",(x)=>x[Index]<[Index] and x[Wykonanie]<>null),
"Index")[Wykonanie],
_Index = 
Table.Max(
Table.SelectRows(#"Changed Type",(x)=>x[Index]<[Index] and x[Wykonanie]<>null),
"Index")[Index]
in
_Wykonanie + 9000 * ([Index] - _Index)
else [Wykonanie]

_Index part will catch the max index whose data is not blank.

 

Best Regards,
Rico Zhou

 

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

4 REPLIES 4
v-rzhou-msft
Community Support
Community Support

Hi @Mpcz ,

 

I suggest you to try this code to create a custom column.

if [Index]>17 then 
Table.Max(
Table.SelectRows(#"Changed Type",(x)=>x[Index]<[Index] and x[Wykonanie]<>null),
"Index")[Wykonanie]
+ 9000 *([Index] - 17)
else [Wykonanie]

Result is as below.

RicoZhou_0-1661407296362.png

 

Best Regards,
Rico Zhou

 

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

 

Thank you for your time and the code you've shared it's quite close to what I need. But is there a chance to modify this part :

+ 9000 *([Index] - 17)

instead of 17 I would need it to use the index of the previous non blank [WYkonanie] row. I think i haven't shared enough data on my screenshot,sorry fot that. The thing is that it would work perfectly if all of the rows after index 17 would be blank but thats not the case with my dataset. Let's say that rows 18-25 are blank and then rows from 26 to 35 are not, so I would need the code to use the Index 35 in the above mentioned part of your code and so on as there would multiple groups of blanks and non blanks values in column [Wykoananie]. 

If that's even possible I woul really apppreciate your help here, and once again thank you for the time you invested so far.

 

Below a little bit more insight on my dataset (please ignore Filled column i tried to modify your code at my own which hasn't really worked):

Mpcz_0-1661518416950.pngMpcz_1-1661518461524.png

 

Hi @Mpcz ,

 

I suggest you to try this code.

if [Index]>17 and [Wykonanie] = null then 
let _Wykonanie = 
Table.Max(
Table.SelectRows(#"Changed Type",(x)=>x[Index]<[Index] and x[Wykonanie]<>null),
"Index")[Wykonanie],
_Index = 
Table.Max(
Table.SelectRows(#"Changed Type",(x)=>x[Index]<[Index] and x[Wykonanie]<>null),
"Index")[Index]
in
_Wykonanie + 9000 * ([Index] - _Index)
else [Wykonanie]

_Index part will catch the max index whose data is not blank.

 

Best Regards,
Rico Zhou

 

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

Thank you @v-rzhou-msft that's exactly what I needed. It's running a bit slow but thats due to the volume of my dataset.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.