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

Fill "null" automaticaly with last year value

Hello,

 

I have the following problem: For some Projects(ProjectID) and some years I do not have exchange rates (FX). 

I need a algorithm which fills the null-cells automatically. It needs to consider following conditions:

 

1. If there is no value for the year before for the specific ProjectID use the FX-Rate of the following year

2. If there is no value for the year after for the specific ProjectID use the FX Rate of the year before

 

BrauTi_0-1653486647365.png

 

 

I really appreciate your support.

3 REPLIES 3
Vijay_A_Verma
Super User
Super User

See the working here - Open a blank query - Home - Advanced Editor - Remove everything from there and paste the below code to test

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("bdBbCsAgDETRveRbikmMj7WI+9+G0lBqp34NHAIX0juJMTMFkihxDY3wMT6YrOFLkNXZ0NPtimzOv/N8KJbHVLW1N4e2pza2M2dnQS/uCb26Z/TmXsHV/zkm", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ProjectID = _t, Year = _t, #"FX-Rate" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"ProjectID", Int64.Type}, {"Year", Int64.Type}, {"FX-Rate", type number}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"ProjectID"}, {{"Temp", each _, type table [ProjectID=nullable number, Year=nullable number, #"FX-Rate"=nullable number]}}),
    #"Removed Columns" = Table.RemoveColumns(#"Grouped Rows",{"ProjectID"}),
    //Function Start
    fxProcess=(Tbl)=>
        let
            #"Filled Down" = Table.FillDown(Tbl,{"FX-Rate"}),
            #"Filled Up" = Table.FillUp(#"Filled Down",{"FX-Rate"})
        in
    #"Filled Up",
    //Function End
    #"Added Custom" = Table.AddColumn(#"Removed Columns", "Custom", each fxProcess([Temp])),
    #"Removed Columns1" = Table.RemoveColumns(#"Added Custom",{"Temp"}),
    #"Expanded Custom" = Table.ExpandTableColumn(#"Removed Columns1", "Custom", {"ProjectID", "Year", "FX-Rate"}, {"ProjectID", "Year", "FX-Rate"})
in
    #"Expanded Custom"

 

Anonymous
Not applicable

Hello, thanks for the extensive feedback. Looks quiet complicated. Unfortunately I do not understand where I have to insert this code. Maybe you can give me a feedback. 

 

Thank you very mich in advance!

Right click on your table in Power BI - Edit Query (to invoke Power Query)

When you are in PQ, Home menu - Advanced Editor - Delete everything after Source line.

From my code copy all starting with #"Changed Type" till end.

Paste into Advanced Editor after Source line (Make sure Source line has a comma at the end)

OK

Close and Apply

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.