Skip to content

Commit a2c61a1

Browse files
committed
change to use final match
1 parent 4b099e0 commit a2c61a1

1 file changed

Lines changed: 8 additions & 7 deletions

File tree

forumQuestions/pq/2024-03 - Using Pairs of Strict Splitters to Simplify Your Parsing Logic -- expanded.pq

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ let
5151
][return],
5252
Rows = #"Changed Type",
5353

54-
// get the crumbs, else throw when it's valid
54+
// Try the more specific type first. if it fails, try the second
5555
Col_Step1 = Table.AddColumn(
5656
Rows, "Step1",
5757
(row) =>
@@ -68,23 +68,24 @@ let
6868
Id = Text.Trim( Crumbs{0} ),
6969
Name = Text.Trim( Crumbs{1} ),
7070
YearEnd = Text.Trim( Crumbs{2} ),
71-
// Name2 = SplitBy_TwoWhitespace( Crumbs{1} ),
72-
// CrumbsWhite = SplitBy_TwoWhitespace( row[Name] ),
7371
NameWithoutYear = Text.BeforeDelimiter( Name, " ", Occurrence.Last ),
74-
YearStart = Text.AfterDelimiter( Name, " ", Occurrence.Last ),
72+
YearStart = Text.AfterDelimiter( Name, " ", {0, RelativePosition.FromEnd } ),
7573
return = [
7674
Id = Id,
7775
Name = NameWithoutYear,
7876
YearStart = YearStart,
7977
YearEnd = YearEnd
8078
]
8179
][return],
82-
Record.Type
80+
schema_ParsedRecord
81+
// Record.Type
8382
),
83+
schema_ParsedRecord = type table [ Id = Int64.Type, Name = text, YearStart = Int64.Type, YearEnd = Int64.Type ],
84+
8485
// error if fields are ever missing:
8586
Step2 = Col_LineAsRecord{0}[Step2],
8687
Custom1 = Col_LineAsRecord,
8788
#"Expanded Step2" = Table.ExpandRecordColumn(Custom1, "Step2", {"Id", "Name", "YearStart", "YearEnd"}, {"Id", "Name", "YearStart", "YearEnd"}),
88-
#"Changed Type1" = Table.TransformColumnTypes(#"Expanded Step2",{{"Id", Int64.Type}, {"Name", type text}})
89+
#"Final Table" = Table.TransformColumnTypes(#"Expanded Step2",{{"Id", Int64.Type}, {"Name", type text}, {"YearStart", Int64.Type}, {"YearEnd", Int64.Type}})
8990
in
90-
#"Changed Type1"
91+
#"Final Table"

0 commit comments

Comments
 (0)