-
Notifications
You must be signed in to change notification settings - Fork 62
/
FixCaseSensitiveDAX.cs
57 lines (49 loc) · 2.17 KB
/
FixCaseSensitiveDAX.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
var sb = new System.Text.StringBuilder();
string newline = Environment.NewLine;
sb.Append("TableName" + '\t' + "MeasureName");
// Fix table names in measures
foreach (var m in Model.AllMeasures.ToList())
{
string origExpr = m.Expression;
string expr = m.Expression.ToLower();
string tableMeasure = m.Table.Name + '\t' + m.Name;
foreach (var t in Model.Tables.Where(a => expr.Contains(a.Name.ToLower() + "[") || expr.Contains(a.Name.ToLower() + "'[")))
{
m.Expression = m.Expression.Replace(t.Name,t.Name,StringComparison.OrdinalIgnoreCase);
if (origExpr != m.Expression && !sb.ToString().Contains(tableMeasure))
{
sb.Append(newline + tableMeasure);
}
}
}
// Fix column names in measures
foreach (var m in Model.AllMeasures.ToList())
{
string origExpr = m.Expression;
string expr = m.Expression.ToLower();
string tableMeasure = m.Table.Name + '\t' + m.Name;
foreach (var c in Model.AllColumns.Where(a => expr.Contains(a.Table.Name.ToLower() + "[" + a.Name.ToLower() + "]") || expr.Contains("'" + a.Table.Name.ToLower() + "'[" + a.Name.ToLower() + "]")))
{
m.Expression = m.Expression.Replace(c.Name,c.Name,StringComparison.OrdinalIgnoreCase);
if (origExpr != m.Expression && !sb.ToString().Contains(tableMeasure))
{
sb.Append(newline + tableMeasure);
}
}
}
// Fix measure names in measures
foreach (var m in Model.AllMeasures.ToList())
{
string origExpr = m.Expression;
string expr = m.Expression.ToLower();
string tableMeasure = m.Table.Name + '\t' + m.Name;
foreach (var c in Model.AllMeasures.Where(a => expr.Contains("[" + a.Name.ToLower() + "]")))
{
m.Expression = m.Expression.Replace(c.Name,c.Name,StringComparison.OrdinalIgnoreCase);
if (origExpr != m.Expression && !sb.ToString().Contains(tableMeasure))
{
sb.Append(newline + tableMeasure);
}
}
}
Info("Object references have been updated to match the actual table, column or measure name within the model for the following measures:" + newline + newline + sb.ToString());