Forum Discussion
v_mark
4 years agoHelper V
Expand the values for dimension table
I do have a dimension table that has this type of format. value category rating_type {1,3} Very Poor Service {4,8} Below Expectation Service {9,15} Meets Expectation Service ...
- 4 years ago
Hi v_mark ,
Try this:
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WqjbUMa5V0lEKSy2qVAjIzy8CsoNTi8oyk1OVYnWA8iY6FiB5p9Sc/HIF14qC1OSSxJLM/Dx0dZY6hqYghb6pqSXF+BQamukYmYBUulYkp6am4FVrZAp3m3t+fgqydCwA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [value = _t, category = _t, rating_type = _t]), extTextBetween = Table.TransformColumns(Source, {{"value", each Text.BetweenDelimiters(_, "{", "}"), type text}}), splitByDelim = Table.SplitColumn(extTextBetween, "value", Splitter.SplitTextByDelimiter(",", QuoteStyle.Csv), {"value.1", "value.2"}), addNumberList = Table.AddColumn(splitByDelim, "numberList", each if [value.2] = null then {Number.From([value.1])..Number.From([value.1])} else {Number.From([value.1])..Number.From([value.2])} ), expandToNewRows = Table.ExpandListColumn(addNumberList, "numberList") in expandToNewRowsI get the following output:
Pete
BA_Pete
Super User
4 years agoHi v_mark ,
Try this:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WqjbUMa5V0lEKSy2qVAjIzy8CsoNTi8oyk1OVYnWA8iY6FiB5p9Sc/HIF14qC1OSSxJLM/Dx0dZY6hqYghb6pqSXF+BQamukYmYBUulYkp6am4FVrZAp3m3t+fgqydCwA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [value = _t, category = _t, rating_type = _t]),
extTextBetween = Table.TransformColumns(Source, {{"value", each Text.BetweenDelimiters(_, "{", "}"), type text}}),
splitByDelim = Table.SplitColumn(extTextBetween, "value", Splitter.SplitTextByDelimiter(",", QuoteStyle.Csv), {"value.1", "value.2"}),
addNumberList = Table.AddColumn(splitByDelim, "numberList", each
if [value.2] = null then {Number.From([value.1])..Number.From([value.1])}
else {Number.From([value.1])..Number.From([value.2])}
),
expandToNewRows = Table.ExpandListColumn(addNumberList, "numberList")
in
expandToNewRows
I get the following output:
Pete