Forum Discussion
Split a Single Column with delimiter [colon]
- Anonymous5 years ago
Hi Ashish_Mathur, Mariusz, Anonymous : Good day! Really appreciate your patience.
I tried to change the last part of the code as below:
------------------------------------------------
#"Expanded data1" = Table.ExpandRecordColumn(#"Expanded data", "data", {"pipelineName", "subject", "startDate", "endDate", "quantityEstimateMMBtu", "impactDescription", "details", "updateDate", "locations"}, {"pipelineName", "subject", "startDate", "endDate", "quantityEstimateMMBtu", "impactDescription", "details", "updateDate", "locations"}),
Split = List.Split(#"Expanded data1", "locations",2),
output =#table(type table[locationId= Int64.Type, LocationName=text], Split)
in
#"Expanded data1"
--------------------------
But still it keeps the ‘locations” Column with ‘List’
If I do as below:
#"Expanded data1" = Table.ExpandRecordColumn(#"Expanded data", "data", {"pipelineName", "subject", "startDate", "endDate", "quantityEstimateMMBtu", "impactDescription", "details", "updateDate", "locations"}, {"pipelineName", "subject", "startDate", "endDate", "quantityEstimateMMBtu", "impactDescription", "details", "updateDate", "locations"}),
Split = List.Split("locations",2),
output =#table(type table[locationId= Int64.Type, LocationName=text], Split)
in
#"Expanded data1"
----------------------
I get same results : ‘List’ in ‘locations’ Column.
I am missing some steps, any help is highly appreciated. Many thanks.
Hi,
So then "After I had to make some M code changes in my data source code to support “Scheduled Refresh” for publishing the dashboard, I now get 'List' in 'locations' column."- this is the problem.
Hi Ashish_Mathur : Good day.
The code for this data source, #2 details_maintenance_events is as below [changing some value with xyz/abc/...], from which I get 'locations' column as a list:
---------------
let
Source = Sql.Database("xyz\Fundamentals", "NatGas_V3", [Query="select * from NatGas_V3.natgas.pipeline_maintenance_events#(lf)where endDate >=" &datefilter]),
#"Sorted Rows" = Table.Sort(Source,{{"endDate", Order.Ascending}, {"updateDate", Order.Descending}}),
#"Filtered Rows" = Table.SelectRows(#"Sorted Rows", each true),
id1 = #"Filtered Rows"[id],
#"Converted to Table" = Table.FromList(id1, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
#"Added Custom" = Table.AddColumn(#"Converted to Table", "Source", each Json.Document(Web.Contents("https://api.abc.com/",
[
Headers=[#"Gen-Api-Key"="........"],
RelativePath="natgas/events/v1/maintenance-events/details",
Query=
[
ids=Text.From([Column1]),
format="json"
]
]))),
#"Removed Errors" = Table.RemoveRowsWithErrors(#"Added Custom", {"Column1"}),
#"Removed Errors1" = Table.RemoveRowsWithErrors(#"Removed Errors", {"Column1"}),
#"Removed Errors2" = Table.RemoveRowsWithErrors(#"Removed Errors1", {"Source"}),
#"Expanded Source" = Table.ExpandRecordColumn(#"Removed Errors2", "Source", {"data"}, {"data"}),
#"Expanded data" = Table.ExpandListColumn(#"Expanded Source", "data")
in
#"Expanded data"
---------------------
First I pull data from a sql database as #1 maintenance_events data source, then I create this 2nd data source, details_maintenance_events. I haven't changed any code in #1 data source[ use get data-> sql database->....], which is as below:
----
let
Source = Sql.Database("xyz\Fundamentals", "NatGas_V3", [Query="select * from NatGas_V3.natgas.pipeline_maintenance_events#(lf)where endDate >=" &datefilter]),
#"Sorted Rows" = Table.Sort(Source,{{"endDate", Order.Ascending}, {"updateDate", Order.Descending}}),
#"Filtered Rows" = Table.SelectRows(#"Sorted Rows", each true)
in
#"Filtered Rows"
--------
How do I change code to get ‘locations’ column as : delimited like location_id:location_name? Many thanks in advance.
- Anonymous5 years agoNot applicable
Hi Ashish_Mathur, Anonymous and all: Good day! Continuation from my previous post:
Now as I try to change the last part of the code to get the LocationId and locationName from ‘locations’ List using Split Column by Delimiter:
#"Expanded data1" = Table.ExpandRecordColumn(#"Expanded data", "data", {"pipelineName", "subject", "startDate", "endDate", "quantityEstimateMMBtu", "impactDescription", "details", "updateDate", "locations"}, {"pipelineName", "subject", "startDate", "endDate", "quantityEstimateMMBtu", "impactDescription", "details", "updateDate", "locations"}),
#"Split Column by Delimiter" = Table.SplitColumn(#"Expanded data1", "locations", Splitter.SplitTextByDelimiter(":", QuoteStyle.Csv), {"locations.1", "locations.2"}),
#"Changed Type" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"locations.1", Int64.Type}, {"locations.2", type text}}),
#"Renamed Columns" = Table.RenameColumns(#"Changed Type",{{"locations.1", "locations.LocationId"}, {"locations.2", "locations.LocationName"}})
in
#"Renamed Columns"
-------------------------------------------
I get errors:
In 'Split Column by Delimiter', I am using "Splitter.SplitTextByDelimiter" - What do I use to get from List? Many thanks in advance.
- Anonymous5 years agoNot applicable
Hi Ashish_Mathur, Mariusz, Anonymous : Good day! Really appreciate your patience.
I tried to change the last part of the code as below:
------------------------------------------------
#"Expanded data1" = Table.ExpandRecordColumn(#"Expanded data", "data", {"pipelineName", "subject", "startDate", "endDate", "quantityEstimateMMBtu", "impactDescription", "details", "updateDate", "locations"}, {"pipelineName", "subject", "startDate", "endDate", "quantityEstimateMMBtu", "impactDescription", "details", "updateDate", "locations"}),
Split = List.Split(#"Expanded data1", "locations",2),
output =#table(type table[locationId= Int64.Type, LocationName=text], Split)
in
#"Expanded data1"
--------------------------
But still it keeps the ‘locations” Column with ‘List’
If I do as below:
#"Expanded data1" = Table.ExpandRecordColumn(#"Expanded data", "data", {"pipelineName", "subject", "startDate", "endDate", "quantityEstimateMMBtu", "impactDescription", "details", "updateDate", "locations"}, {"pipelineName", "subject", "startDate", "endDate", "quantityEstimateMMBtu", "impactDescription", "details", "updateDate", "locations"}),
Split = List.Split("locations",2),
output =#table(type table[locationId= Int64.Type, LocationName=text], Split)
in
#"Expanded data1"
----------------------
I get same results : ‘List’ in ‘locations’ Column.
I am missing some steps, any help is highly appreciated. Many thanks.
- Anonymous5 years agoNot applicable
Hi all: Good day! I found checking the data in the data base table and Api portal that for some pipes there will be same event posted for different locations [as they are impacted for all those locations for a pipeline]. That's why the multiple location rows are coming for those pipes! So, it's actually not an error/issue, but a fact! So, I am closing this thread. Thanks all for your patience. 🙂