Last active
August 29, 2023 08:48
-
-
Save otykier/de42cdbf30225ccbaf7f1fc67d357f3f to your computer and use it in GitHub Desktop.
Convert legacy (SQL) partitions to M (Power Query)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This Tabular Editor script will convert all legacy (SQL) partitions on a model, to corresponding M | |
// (Power Query) partitions, that use the Value.NativeQuery function on the original SQL expression. | |
// The script can be used in both TE2 and TE3. | |
const string mQuery = "let\n Source = #\"{0}\",\n Data = Value.NativeQuery(Source, \"{1}\")\nin\n Data"; | |
foreach(var table in Model.Tables.Where(t => t.SourceType == PartitionSourceType.Query)) | |
{ | |
table.Partitions.ConvertToPowerQuery(); | |
foreach(MPartition partition in table.Partitions) | |
{ | |
partition.Expression = string.Format(mQuery, | |
Model.DataSources.First().Name, | |
partition.Expression.Replace("\"", "\"\"")); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment