2016-11-23 122 views
0

過去我創建了一個.pbix文件,並以Azure DocumentDB作爲源文件。現在,屬於DocumentDB的數據庫名稱已更改爲帶有破折號的名稱(即ebsaz-ddbesb-telemetry-o),這似乎會導致Power BI的編輯查詢屏幕中的高級編輯器下的M語法出現一些問題。如何逃避M語言中的特殊字符(Power BI)?

我認爲應該有一個簡單的方法來轉義特殊字符(在這種情況下是破折號),例如單引號或雙引號,方括號,正方括號等。我嘗試了各種括號和引號,但它沒有似乎沒有解決它。以下是M語言代碼,感謝您的幫助:

let 
Source = DocumentDB.Contents("https://ebsaz-ddbesb-301.documents.azure.com:443/"), 
ebsaz-ddbesb-telemetry-o = Source{[id="ebsaz-ddbesb-telemetry-o"]}[Collections], 
ebsaz-ddbesb-telemetry-o_ElectricityTelemetryData = ebsaz-ddbesb-telemetry-o{[db_id="ebsaz-ddbesb-telemetry-o",id="ElectricityTelemetryData"]}[Documents], 
#"Expanded Document" = Table.ExpandRecordColumn(ebsaz-ddbesb-telemetry-o_ElectricityTelemetryData, "Document", {"dataAccessPointid", "eanCode", "electricityUsageLowkWh", "electricityUsageNormalkWh", "id", "dataSource", "timeStamp"}, {"Document.dataAccessPointid", "Document.eanCode", "Document.electricityUsageLowkWh", "Document.electricityUsageNormalkWh", "Document.id", "Document.dataSource", "Document.timeStamp"}), 
#"Reordered Columns" = Table.ReorderColumns(#"Expanded Document",{"Document.id", "Document.dataAccessPointid", "Document.eanCode", "Document.ElectricityUsageLowkWh", "Document.ElectricityUsageNormalkWh", "Document.dataSource", "Document.timeStamp"}), 
#"Changed Type" = Table.TransformColumnTypes(#"Reordered Columns",{{"Document.id", type text}}), 
#"Renamed Columns" = Table.RenameColumns(#"Changed Type",{{"Document.id", "GUID"}}), 
#"Changed Type1" = Table.TransformColumnTypes(#"Renamed Columns",{{"Document.dataAccessPointid", Int64.Type}}), 
#"Renamed Columns1" = Table.RenameColumns(#"Changed Type1",{{"Document.dataAccessPointid", "DATAACCESSPOINTID"}}), 
#"Changed Type2" = Table.TransformColumnTypes(#"Renamed Columns1",{{"Document.eanCode", Int64.Type}}), 
#"Renamed Columns2" = Table.RenameColumns(#"Changed Type2",{{"Document.eanCode", "EANCODE"}}), 
#"Changed Type3" = Table.TransformColumnTypes(#"Renamed Columns2",{{"Document.ElectricityUsageLowkWh", type number}}), 
#"Renamed Columns3" = Table.RenameColumns(#"Changed Type3",{{"Document.ElectricityUsageLowkWh", "ElectricityUsageLowkWh"}}), 
#"Changed Type4" = Table.TransformColumnTypes(#"Renamed Columns3",{{"Document.ElectricityUsageNormalkWh", type number}}), 
#"Renamed Columns4" = Table.RenameColumns(#"Changed Type4",{{"Document.ElectricityUsageNormalkWh", "ElectricityUsageNormalkWh"}}), 
#"Changed Type5" = Table.TransformColumnTypes(#"Renamed Columns4",{{"Document.dataSource", type text}}), 
#"Renamed Columns5" = Table.RenameColumns(#"Changed Type5",{{"Document.dataSource", "DataSource"}}), 
#"Changed Type6" = Table.TransformColumnTypes(#"Renamed Columns5",{{"Document.timeStamp", type datetimezone}}), 
#"Split Column by Delimiter" = Table.SplitColumn(Table.TransformColumnTypes(#"Changed Type6", {{"Document.timeStamp", type text}}, "en-US"),"Document.timeStamp",Splitter.SplitTextByEachDelimiter({" "}, QuoteStyle.Csv, true),{"Document.timeStamp.1", "Document.timeStamp.2"}), 
#"Changed Type7" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Document.timeStamp.1", type datetime}, {"Document.timeStamp.2", type text}}), 
#"Renamed Columns6" = Table.RenameColumns(#"Changed Type7",{{"Document.timeStamp.1", "MeasurementDateTime"}, {"Document.timeStamp.2", "MeasurementTimezoneOffset"}}), 
#"Sorted Rows" = Table.Sort(#"Renamed Columns6",{{"MeasurementDateTime", Order.Descending}}), 
#"Renamed Columns7" = Table.RenameColumns(#"Sorted Rows",{{"ElectricityUsageLowkWh", "Dal"}, {"ElectricityUsageNormalkWh", "Piek"}}), 
#"Changed Type8" = Table.TransformColumnTypes(#"Renamed Columns7",{{"EANCODE", type text}}), 
#"Sorted Rows1" = Table.Sort(#"Changed Type8",{{"MeasurementDateTime", Order.Ascending}}), 
#"Added Custom1" = Table.AddColumn(#"Sorted Rows1", "PercentageContractVermogenKW", each (([Piek]+[Dal])*4)/800), 
#"Changed Type9" = Table.TransformColumnTypes(#"Added Custom1",{{"PercentageContractVermogenKW", type number}}), 
#"Inserted Date" = Table.AddColumn(#"Changed Type9", "Date", each DateTime.Date([MeasurementDateTime]), type date), 
#"Renamed Columns8" = Table.RenameColumns(#"Inserted Date",{{"Date", "MeasurementDate"}}), 
#"Inserted Time" = Table.AddColumn(#"Renamed Columns8", "Time", each DateTime.Time([MeasurementDateTime]), type time), 
#"Renamed Columns9" = Table.RenameColumns(#"Inserted Time",{{"Time", "MeasurementEndTime"}}) 
in 
#"Renamed Columns9" 

回答

0

幸運的是,修復非常簡單。只要改變這三條線,並使用#""逃逸:

#"ebsaz-ddbesb-telemetry-o" = Source{[id="ebsaz-ddbesb-telemetry-o"]}[Collections], 
#"ebsaz-ddbesb-telemetry-o_ElectricityTelemetryData" = #"ebsaz-ddbesb-telemetry-o"{[db_id="ebsaz-ddbesb-telemetry-o",id="ElectricityTelemetryData"]}[Documents], 
#"Expanded Document" = Table.ExpandRecordColumn(#"ebsaz-ddbesb-telemetry-o_ElectricityTelemetryData", "Document", {"dataAccessPointid", "eanCode", "electricityUsageLowkWh", "electricityUsageNormalkWh", "id", "dataSource", "timeStamp"}, {"Document.dataAccessPointid", "Document.eanCode", "Document.electricityUsageLowkWh", "Document.electricityUsageNormalkWh", "Document.id", "Document.dataSource", "Document.timeStamp"}), 
+0

感謝您的回覆格雷格!最終找到了一個不同的解決方案,但爲了將來的參考,我一定會記得hashtags是答案。 –