Great post, thanks for sharing.
Tabular Editor users may want to use the following C# script, which does the same thing (converting SQL partitions to M/Power Query partitions on the currently loaded model):
// 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:
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("\"", "\"\""));
}
}