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

Level up your Power BI skills this month - build one visual each week and tell better stories with data! Get started

Reply
Mohan1005
Regular Visitor

Row duplication and updation

Hi,

 

I need help in power query to achieve the following scenario. if we are comparing current month id's with previous months id's and if some id's are not present in the current month and present in previous month i need these records to be inserted as duplicates in the current month with updation of month column.

 

please find the tables for better understanding.

Existing Table
MonthYearID
420191
420192
520191
520193
620194
620195

 

Updated Table
MonthYearID
420191
420192
520191
520192
520193
620191
620192
620193
620194
620195

 

Thanks and Regards in advance

1 ACCEPTED SOLUTION
Zubair_Muhammad
Community Champion
Community Champion

@Mohan1005 

 

Please try this one

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlHSUTIyMLQEUoZKsTooAkZgAVN0FUgCxmABM4SACbqAqVJsLAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Month = _t, Year = _t, ID = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Month", Int64.Type}, {"Year", Int64.Type}, {"ID", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each let myIDs=Table.SelectRows(#"Changed Type",(x)=>(x)[Month]<=[Month] 
and (x)[Year]<=[Year])[ID]
in {List.Min(myIDs)..List.Max(myIDs)}),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"ID"}),
    #"Removed Duplicates" = Table.Distinct(#"Removed Columns", {"Month", "Year"}),
    #"Expanded Custom" = Table.ExpandListColumn(#"Removed Duplicates", "Custom")
in
    #"Expanded Custom"

View solution in original post

2 REPLIES 2
Zubair_Muhammad
Community Champion
Community Champion

@Mohan1005 

 

Please try this one

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlHSUTIyMLQEUoZKsTooAkZgAVN0FUgCxmABM4SACbqAqVJsLAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Month = _t, Year = _t, ID = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Month", Int64.Type}, {"Year", Int64.Type}, {"ID", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each let myIDs=Table.SelectRows(#"Changed Type",(x)=>(x)[Month]<=[Month] 
and (x)[Year]<=[Year])[ID]
in {List.Min(myIDs)..List.Max(myIDs)}),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"ID"}),
    #"Removed Duplicates" = Table.Distinct(#"Removed Columns", {"Month", "Year"}),
    #"Expanded Custom" = Table.ExpandListColumn(#"Removed Duplicates", "Custom")
in
    #"Expanded Custom"

Hi Zubair,

 

Great Work. The solution provided from your end is working fine with the integer column. But if i'm trying the same with Text column this cant be applied. 
kindly guide me through a solution to over come this barrier.


please find the sample data for the same.

YearMonthProject IdYes/NoYTD Yes/No
20194836-0111
201944396-0100
201944658-0100
201954658-0110
201954960-0111
201955086-36NULL1
201965086-36NULL1
20196594-0111
20196597-0111


Thanks and Regards in advance

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

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

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

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.