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

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
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!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 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.