Forum Discussion
Baskar
8 years agoResident Rockstar
Add Dynamic Rows in Power Query
Thanks Advanced !!!
I have below datset with dens value, in this dataset dens value with missing contunious number.
Current DatasetExpected Dataset
Sorry Baskar,
my fault. Here it comes:
let CreateRowsFunction = (Partition) => let Source = Partition, AddedIndex = Table.AddIndexColumn(Source, "Index", 0, 1), #"Added Custom" = Table.AddColumn(AddedIndex, "Custom", each try { [Dense Value] .. AddedIndex[Dense Value]{[Index]+1}-1 } otherwise {[Dense Value]}), #"Expanded Custom" = Table.ExpandListColumn(#"Added Custom", "Custom"), #"Added Custom1" = Table.AddColumn(#"Expanded Custom", "Custom.1", each if [Custom]=[Dense Value] or [Custom] = null then [Count] else 0) in #"Added Custom1", Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("Zc+xEQAhCATAXogNHk5RanHsv40HP/EluWBn4GBOsgcM61TIRDxZaJUf4/FEZvbMGjvGOHgECDwrEmtwu3k3StIoRD3YHLpGY7u1xwrVxLxHEn+fI/k+2y9ZLw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Ticket = _t, #"Dense Value" = _t, Count = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Dense Value", Int64.Type}, {"Count", Int64.Type}}), #"Grouped Rows" = Table.Group(#"Changed Type", {"Ticket"}, {{"Partition", each _, type table}}), #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each CreateRowsFunction([Partition])), #"Expanded Custom" = Table.ExpandTableColumn(#"Added Custom", "Custom", {"Custom", "Custom.1"}, {"Dense Value", "Count"}), #"Removed Columns" = Table.RemoveColumns(#"Expanded Custom",{"Partition"}) in #"Removed Columns"Please check out this new code:
let CreateRowsFunction = (Partition) => let Source = Table1, #"Sorted Rows" = Table.Sort(Source,{{"Dense Value", Order.Ascending}}), AddedIndex = Table.AddIndexColumn(#"Sorted Rows", "Index", 0, 1), Custom1 = Table.AddColumn(AddedIndex, "Intervals", each try (AddedIndex[Dense Value]{[Index]+1}*10 - [Dense Value]*10) / 2 otherwise 0), #"Added Custom1" = Table.AddColumn(Custom1, "Custom", each {0..[Intervals] - 1}), #"Added Custom" = Table.AddColumn(#"Added Custom1", "Add", each List.Transform([Custom], (x) => x * 0.2)), #"Expanded Add" = Table.ExpandListColumn(#"Added Custom", "Add"), #"Replaced Value" = Table.ReplaceValue(#"Expanded Add",null,0,Replacer.ReplaceValue,{"Add"}), #"Inserted Addition" = Table.AddColumn(#"Replaced Value", "NewDense", each [Dense Value] + [Add], type number), #"Removed Other Columns" = Table.SelectColumns(#"Inserted Addition",{"Ticket", "Dense Value", "Count", "NewDense"}) in #"Removed Other Columns" , Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUTI20jMCUkZKsTpwATMQhRAw1rMAUiYIARMgYYrEBWswQxYAaTBHCJiiypuCrTRFFkCz0hRsAtBRsQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Ticket = _t, #"Dense Value" = _t, Count = _t]), #"Changed Type1" = Table.TransformColumnTypes(Source,{{"Dense Value", type number}, {"Count", type number}}), #"Grouped Rows" = Table.Group(#"Changed Type1", {"Ticket"}, {{"Partition", each _, type table}}), #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each CreateRowsFunction([Partition])), #"Expanded Custom" = Table.ExpandTableColumn(#"Added Custom", "Custom", {"Dense Value", "Count", "NewDense"}, {"Dense Value", "Count", "NewDense"}), #"Removed Columns" = Table.RemoveColumns(#"Expanded Custom",{"Partition"}) in #"Removed Columns"
17 Replies
Replies have been turned off for this discussion
- Zubair_MuhammadCommunity Champion
Hi Baskar
Sorry I am not very good in Power Query
But this DAX calculated table should work
Calculated Table = VAR temp = GENERATE ( VALUES ( Table1[Ticket_INTL_ID] ), VAR maxvalue = MAXX ( RELATEDTABLE ( Table1 ), [Dens_Value] ) VAR minvalue = MINX ( RELATEDTABLE ( Table1 ), [Dens_Value] ) RETURN SELECTCOLUMNS ( EXCEPT ( GENERATESERIES ( minvalue, maxvalue ), CALCULATETABLE ( VALUES ( Table1[Dens_Value] ) ) ), "Dense_Value", [Value] ) ) VAR temp1 = ADDCOLUMNS ( temp, "Dense Count", 0 ) RETURN UNION ( Table1, temp1 )- BaskarResident Rockstar
Thanks for very quick response Zubair_Muhammad.
Here am looking for power query operation. after that i have few ETL operations.
- Zubair_MuhammadCommunity Champion
- Zubair_MuhammadCommunity Champion