Forum Discussion
nareshr89
4 years agoHelper II
Adding rows to an existing table in Power BI
I have a table that is used to format the KPI to a specific buckets based on header and each KPI has a sorting order number. I would like to add new rows under multiple places and want the sorting or...
Chewdata
9 months agoResponsive Resident
Maybe the following is a solution for your problem. With Table.InsertRows you can insert an new record at a given index. Not sure if your sort column is dynamic or static. For this to work you would need to add a dynamic indexColumn for the sorting.
See the code below for an example:
let
// replace the source with your data
Source = YOURDATA,
// a list with the record for the new kpi
newKPI = {[
Attributes_PnL_Format = "np_totalCost",
Category = "Revenue by source",
New_PNL_Name = "Total Cost"
]},
// insert the record at the desired position
add_newRecord = Table.InsertRows(
Source,
1, // the position you want it to be inserted at
newKPI // the record
),
// create a index column that can be used for sorting
add_sortOrder = Table.AddIndexColumn(
add_newRecord,
"SortOrder",
0,
1,
Int64.Type
)
in
add_sortOrder