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

Learn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register now

Reply
desmondmclellan
New Member

Add a conditional column using a conditional test referencing previous record

In the data below the original source information is reflected in columns called "Date","Start Time" and "End Time"

I add a new column called "Date Cleaned" and in this column I would like to relect the formula in column called "Formlula". In essence I want to add a date in in this column based on a condition thereby ensuring the correct date is added. Easy in excel but I am finding it difficult in Power Query. Any assistance would be greatly appreciated. 

 

 

 ABCDE
4DateDate CleanedFormulaStart TimeEnd Time
5Fri 01-Dec-2023Fri 01-Dec-2023if (A5<>0,A5,B4)7:30AM9:15AM
6 Fri 01-Dec-2023if (A6<>0,A6,B5)9:15AM10:30AM
7 Fri 01-Dec-2023if (A7<>0,A7,B6)10:30AM11:00AM
8 Fri 01-Dec-2023if (A7<>0,A8,B7)11:00AM12:30PM
9 Fri 01-Dec-2023if (A7<>0,A9,B8)12:30PM1:00PM
10 Fri 01-Dec-2023if (A7<>0,A10,B9)1:00PM2:00PM
11 Fri 01-Dec-2023if (A7<>0,A11,B10)4:00PM5:06PM
12Mon 04-Dec-2023Mon 04-Dec-2023if (A7<>0,A12,B11)8:00AM9:15AM
13 Mon 04-Dec-2023etc9:15AM11:00AM
14 Mon 04-Dec-2023 11:00AM11:30AM
15 Mon 04-Dec-2023 11:30AM12:30PM
16 Mon 04-Dec-2023 12:30PM1:30PM
17 Mon 04-Dec-2023 1:30PM3:36PM

 

1 ACCEPTED SOLUTION

I am giving a very simple solution to you which doesn't require Index.

Create a duplicate column named Date Cleaned, Fill down on this column and Reorder this column

let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Duplicated Column" = Table.DuplicateColumn(Source, "Content.Date", "Date Cleaned"),
    #"Filled Down" = Table.FillDown(#"Duplicated Column",{"Date Cleaned"}),
    #"Reordered Columns" = Table.ReorderColumns(#"Filled Down",{"Index", "Content.Date", "Date Cleaned", "Content.Start Time", "Content.End Time", "Content.Time Code"})
in
    #"Reordered Columns"

View solution in original post

6 REPLIES 6
Vijay_A_Verma
Most Valuable Professional
Most Valuable Professional

Easiest way is to insert an Index column and put following formula in a custom column where #"Added Index" is previous step

if [Date] = null or [Date] = "" then try #"Added Index"[Date Cleaned]{[Index]-1} otherwise null else [Date]

Thanks Vijay.

 

It did not work because Power Query gave me error in that it said [Date Cleaned] wasnt defined. However it did put me on the path to solving it by adding a new column replicating the values in Date Column and then using Table.ReplaceValue function. Error is no longer there, howeve the logic for Table.Replace Function does not give me the answer I need. It is meant to replace all those that are "null" with the date above it so that all nulls have a date in the field. So help in solving this would be appreciated. See Table and code belowTable.pngCode.png

if you could create an Excel file with some dummy data and upload the file to any file hosing service like Onedrive, Google drive, Box, Dropbox etc and share me the link here, I can give the solution which you are seeking. 

I have created a file and it is located here with dummy data. Column C is what I want to end up with.

 

https://1drv.ms/x/s!Av2xPMKBTIxvg_RY-6DYWK-b-lY4hw?e=7Fsd9d 

I am giving a very simple solution to you which doesn't require Index.

Create a duplicate column named Date Cleaned, Fill down on this column and Reorder this column

let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Duplicated Column" = Table.DuplicateColumn(Source, "Content.Date", "Date Cleaned"),
    #"Filled Down" = Table.FillDown(#"Duplicated Column",{"Date Cleaned"}),
    #"Reordered Columns" = Table.ReorderColumns(#"Filled Down",{"Index", "Content.Date", "Date Cleaned", "Content.Start Time", "Content.End Time", "Content.Time Code"})
in
    #"Reordered Columns"

Thanks a much easier solution. A function I did not know existed but will use again. 

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

February Power BI Update Carousel

Power BI Monthly Update - February 2026

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

Top Solution Authors