Something like this could be useful if you have a large MDX script and want to translate some codes from one set to another set. (Perhaps I should find a more compact representation for the code translation table, like JSON, or even just a delimited string. I miss Perl’s quoting and literal syntaxes, sometimes…)
A script I just wrote; slight changes to the “pat” to make it less specific to the cube I’m working on. Edit as necessary.
open System open System.IO open System.Text.RegularExpressions let filename = @"c:\temp\mdxscript.txt" let txt = File.ReadAllText filename let pat = "(\[yourDimensionName\]\.\[yourHierarchyName\]\.&\[)(\d+)(\])" let oldToSnomed = Map.ofList [ "oldcode1", "snowmedcode1"; "oldcode2", "snowmedcode2"] let replacer (m:Match) = let orig = m.Captures..Value let before = m.Groups..Value let code = m.Groups..Value let after = m.Groups..Value printfn "%s" code let converted = oldToSnomed.TryFind(code) match converted with | Some snomed -> before + snomed + after | _ -> orig let evaluator = new MatchEvaluator(replacer) let txt2 = Regex.Replace(txt, pat, evaluator) txt2 File.WriteAllText(filename, txt2) // overwrites with translated codes