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

undefined

Hello,

I Have a table

analyst__0-1687450771631.png

I need to create a row for each bolded row value such that I get contract month for the prior month.
this is how the end result should look like 

analyst__1-1687450814600.png


I tried to use the following Power Query code to do this

= let
createPriorMonthRow = (table as table) =>
let
currentDate = DateTime.LocalNow(),
currentMonth = Date.Month(currentDate),
priorMonth = Date.AddMonths(currentDate, -1),
priorMonthValue = Date.StartOfMonth(priorMonth),

filteredRows = Table.SelectRows(table, each Date.Month([Contract Month]) = currentMonth and [Custom] = "Yes"),

duplicatedRows = Table.FromRecords(List.Transform(Table.ToRecords(filteredRows), each Record.FromList(Record.ToList(_) & {priorMonthValue}, Table.ColumnNames(table) & {"Contract Month"}))),

updatedTable = Table.Combine({table, duplicatedRows})

in
updatedTable,
// Example usage#(cr)#(lf)
source = SampleTest,
updatedTable = createPriorMonthRow
in
updatedTable

but it gvies me an error saying:
Expression.Error: Expected a TransformOperations value. Details: [List]

I am not really well versed with Power Query M COde, so not understanding where i am going wrong

Any help would be appreciated.
Thanks

1 REPLY 1
Anonymous
Not applicable

Hi @Anonymous ,

 

Below is the method to get value from previsou row in Power Query. Please refer to

Value from previous row – Power Query, M language – Trainings, consultancy, tutorials (exceltown.com)

You need to set a grouping as a column for your bold font row. Bold characters are not recognized in Power Query as a basis for grouping.

 

Best Regards,

Stephen Tao

 

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

Helpful resources

Announcements
Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

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.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.