Forum Discussion
ruhor
10 years agoFrequent Visitor
Parsing Multiple Measures From a String in DAX
I have a DB table that contains water meter information for tiered billing: meterid name graduated mincharge ranges standardcalculation
------------------------------------------------------...
Greg_Deckler
10 years agoCommunity Champion
ruhor - A possible implementation along the lines of what greggyb was suggesting. Required two splits and two unpivots. This was from using your sample data in an "Enter Data" query.
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("bZDJCsIwEIZfRXKsMk7SZjurL+CCh9KDSlChKLQuCDl49y19EidpBavmkJlJ5v9myXNm2YDNzof1udr2lquTqyieTxcTMlyDlWQlInodLhsPPY0SQBQy6cccH8PWKMGKQc44Utr0WLvLvizdN1qDkrGCN9knVYPghFHAAy0DIxsY78Bm7trpE4ELsg3HtyAUPmpF+Bqvbqfj4WfAFDLbFQ45zZmkoKiBRq5j6c3O1aT9JoQhtecKvQj7Md0lBRixjPVvV5h/Lqat+7w/QsSK4gU=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [meterid = _t, name = _t, graduated = _t, mincharge = _t, ranges = _t, standardcalculation = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"meterid", Int64.Type}, {"name", type text}, {"graduated", type logical}, {"mincharge", type number}, {"ranges", type text}, {"standardcalculation", type text}}),
#"Split Column by Delimiter" = Table.SplitColumn(#"Changed Type","ranges",Splitter.SplitTextByDelimiter("|", QuoteStyle.Csv),{"ranges.1", "ranges.2", "ranges.3", "ranges.4", "ranges.5"}),
#"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"ranges.1", Int64.Type}, {"ranges.2", Int64.Type}, {"ranges.3", Int64.Type}, {"ranges.4", type text}, {"ranges.5", type text}}),
#"Split Column by Delimiter1" = Table.SplitColumn(#"Changed Type1","standardcalculation",Splitter.SplitTextByDelimiter("|", QuoteStyle.Csv),{"standardcalculation.1", "standardcalculation.2", "standardcalculation.3", "standardcalculation.4", "standardcalculation.5"}),
#"Changed Type2" = Table.TransformColumnTypes(#"Split Column by Delimiter1",{{"standardcalculation.1", type text}, {"standardcalculation.2", type text}, {"standardcalculation.3", type text}, {"standardcalculation.4", type text}, {"standardcalculation.5", type text}}),
#"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type2", {"meterid", "name", "graduated", "mincharge", "ranges.1", "ranges.2", "ranges.3", "ranges.4", "ranges.5"}, "Attribute", "Value"),
#"Unpivoted Other Columns1" = Table.UnpivotOtherColumns(#"Unpivoted Other Columns", {"meterid", "name", "graduated", "mincharge", "Attribute", "Value"}, "Attribute.1", "Value.1")
in
#"Unpivoted Other Columns1"