Forum Discussion
Find the missing number in Sequency
- 3 years ago
MightyRabbit
The solution you linked to is in DAX, and that will work. This solution is in Power Query. Here is the result:Here is what I did:
- Found the series base - F65, F66, etc.
- Extracted the numerical portion - 1234 for example
- Grouped by the series base and added all data to nested tables
- Added a list of missing numbers by getting the min/max of each series base and creating a full list of those numbers, then removing those that already existed. So for F65 it returned a list of 1236 and 1237
- Expanded those missing numbers and added the series base back to them, then added a column that simply said "Missing"
- Removed unnecessary columns
- Appended the missing numbers to the original table.
Here is the code:
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcjMzNTQyNlGK1YGxTZHYFkhsSyjbDKjcFIlthsQ2R2ID1ccCAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Series = _t]), #"Added Series Base" = Table.AddColumn(Source, "Series Base", each Text.Start([Series],3), type text), #"Added Numbers" = Table.AddColumn(#"Added Series Base", "Numbers", each Number.From(Text.AfterDelimiter([Series], [Series Base])), Int64.Type), #"Grouped Rows" = Table.Group( #"Added Numbers", {"Series Base"}, { { "All Rows", each _, type table [Series=nullable text, Series Base=text, Numbers=number] } } ), #"Added Missing Numbers" = Table.AddColumn( #"Grouped Rows", "Missing Numbers", each let varAllNumbers = {List.Min([All Rows][Numbers])..List.Max([All Rows][Numbers])}, varExistingNumbers = [All Rows][Numbers] in List.Difference(varAllNumbers, varExistingNumbers) ), #"Expanded Missing Numbers" = Table.ExpandListColumn(#"Added Missing Numbers", "Missing Numbers"), #"Added Full Series" = Table.AddColumn(#"Expanded Missing Numbers", "Full Series", each [Series Base] & Text.From([Missing Numbers])), #"Added Is Missing" = Table.AddColumn(#"Added Full Series", "Is Missing", each "Missing"), #"Removed Other Columns" = Table.SelectColumns(#"Added Is Missing",{"Full Series", "Is Missing"}), #"Renamed Columns" = Table.RenameColumns(#"Removed Other Columns",{{"Full Series", "Series"}}), #"Appended Query" = Table.Combine({Source, #"Renamed Columns"}), #"Changed Type" = Table.TransformColumnTypes(#"Appended Query",{{"Series", type text}, {"Is Missing", type text}}) in #"Changed Type"How to get good help fast. Help us help you.
How To Ask A Technical Question If you Really Want An Answer
How to Get Your Question Answered Quickly - Give us a good and concise explanation
How to provide sample data in the Power BI Forum - Provide data in a table format per the link, or share an Excel/CSV file via OneDrive, Dropbox, etc.. Provide expected output using a screenshot of Excel or other image. Do not provide a screenshot of the source data. I cannot paste an image into Power BI tables.
Hi edhans ,
Thank you very much for taking your time to look into this. This works as well.
Best regarsd,