Skip to content

Commit 79d245e

Browse files
committed
more properly navigating the bi-directional relationships in Tabular models for the Printer Friendly Dimension Usage Bus Matrix report
1 parent ba9c677 commit 79d245e

3 files changed

Lines changed: 64 additions & 14 deletions

File tree

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
################################################################################
2+
# This .gitignore file was automatically created by Microsoft(R) Visual Studio.
3+
################################################################################
4+
5+
/bin/Debug
6+
/obj/Debug
7+
/.vs/SQL2017_BidsHelper/v14/.suo

SQL2017_BidsHelper.csproj.user

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
4+
<StartAction>Program</StartAction>
5+
<StartProgram>C:\Program Files %28x86%29\Microsoft Visual Studio 14.0\Common7\IDE\devenv.exe</StartProgram>
6+
<StartArguments>/rootsuffix Exp</StartArguments>
7+
</PropertyGroup>
8+
</Project>

SSAS/PrinterFriendlyDimensionUsage.cs

Lines changed: 49 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ public static List<DimensionUsage> GetTabularDimensionUsage(DataModelingSandboxW
178178
}
179179
if (!bFoundVisibleMeasure && bIsBusMatrix) continue;
180180

181-
List<DimensionUsage> tmp = RecurseTabularRelationships(table, table, bIsBusMatrix);
181+
List<DimensionUsage> tmp = RecurseTabularRelationships(table, table, bIsBusMatrix, new List<Microsoft.AnalysisServices.BackEnd.Relationship>(), false);
182182
dimUsage.AddRange(tmp);
183183

184184
if (bFoundVisibleAttribute && bFoundVisibleMeasure) //if this table had a measure but no dimension relationships (except to itself)
@@ -287,30 +287,61 @@ private static List<DimensionUsage> RecurseTabularRelationships(Dimension dMG, M
287287
return list;
288288
}
289289

290-
private static List<DimensionUsage> RecurseTabularRelationships(DataModelingTable dimensionTable, DataModelingTable outerFactTable, bool bIsBusMatrix)
290+
private static List<DimensionUsage> RecurseTabularRelationships(DataModelingTable dimensionTable, DataModelingTable outerFactTable, bool bIsBusMatrix, List<Microsoft.AnalysisServices.BackEnd.Relationship> listRelationshipsTraversed, bool bManyToMany)
291291
{
292292
List<DimensionUsage> list = new List<DimensionUsage>();
293293
foreach (Microsoft.AnalysisServices.BackEnd.Relationship relOuter in dimensionTable.Sandbox.Relationships.RelationshipCollection)
294294
{
295-
if (relOuter.FromColumn.Table.Name != dimensionTable.Name) continue; //find any relationships that start from the "dimensionTable" table
295+
if (listRelationshipsTraversed.Contains(relOuter)) continue; //don't double back on path
296296

297-
string sActiveFlag = "Active";
297+
DataModelingColumn reportedDimensionColumn = null;
298+
DimensionUsage usage = null;
299+
bool bThisRelationshipManyToMany = bManyToMany;
300+
string sRelationshipType = "Active";
298301
if (!relOuter.Active)
299302
{
300-
sActiveFlag = "Inactive";
303+
sRelationshipType = "Inactive";
301304
if (bIsBusMatrix) continue; //don't show inactive relationships in bus matrix view
302305
}
303-
304-
DimensionUsage usage = new DimensionUsage(sActiveFlag, outerFactTable, relOuter.ToColumn.Table);
305-
usage.Column1Name = "Foreign Key Column";
306-
usage.Column1Value = relOuter.FromColumn.Name;
307-
usage.Column2Name = "Primary Key Column";
308-
usage.Column2Value = relOuter.ToColumn.Name;
306+
307+
if (bThisRelationshipManyToMany)
308+
sRelationshipType = "Many to Many";
309+
310+
if (relOuter.ToColumn.Table.Name == dimensionTable.Name
311+
&& relOuter.CrossFilterDirection == Microsoft.AnalysisServices.BackEnd.CrossFilterDirection.Both
312+
&& relOuter.Active)
313+
{
314+
sRelationshipType = "Many to Many";
315+
reportedDimensionColumn = relOuter.FromColumn;
316+
bThisRelationshipManyToMany = true;
317+
318+
usage = new DimensionUsage(sRelationshipType, outerFactTable, reportedDimensionColumn.Table);
319+
usage.Column1Name = "Foreign Key Column";
320+
usage.Column1Value = relOuter.ToColumn.Name;
321+
usage.Column2Name = "Primary Key Column";
322+
usage.Column2Value = relOuter.FromColumn.Name;
323+
324+
}
325+
else if (relOuter.FromColumn.Table.Name != dimensionTable.Name)
326+
{
327+
continue; //find any relationships that start from the "dimensionTable" table
328+
}
329+
else
330+
{
331+
reportedDimensionColumn = relOuter.ToColumn;
332+
333+
usage = new DimensionUsage(sRelationshipType, outerFactTable, reportedDimensionColumn.Table);
334+
usage.Column1Name = "Foreign Key Column";
335+
usage.Column1Value = relOuter.FromColumn.Name;
336+
usage.Column2Name = "Primary Key Column";
337+
usage.Column2Value = relOuter.ToColumn.Name;
338+
}
339+
309340

310341
bool bFoundVisibleAttribute = false;
311-
foreach (DataModelingColumn col in relOuter.ToColumn.Table.Columns)
342+
foreach (DataModelingColumn col in reportedDimensionColumn.Table.Columns)
312343
{
313-
if (!relOuter.ToColumn.Table.IsPrivate && !col.IsPrivate && col.IsAttributeHierarchyQueriable)
344+
if (!col.Table.IsPrivate && !col.IsPrivate && col.IsAttributeHierarchyQueriable)
314345
{
315346
bFoundVisibleAttribute = true;
316347
break;
@@ -321,8 +352,12 @@ private static List<DimensionUsage> RecurseTabularRelationships(DataModelingTabl
321352

322353
if (bIsBusMatrix)
323354
{
355+
List<Microsoft.AnalysisServices.BackEnd.Relationship> listLatestRelationshipsTraversed = new List<Microsoft.AnalysisServices.BackEnd.Relationship>();
356+
listLatestRelationshipsTraversed.AddRange(listRelationshipsTraversed);
357+
listLatestRelationshipsTraversed.Add(relOuter);
358+
324359
//recurse if it's the bus matrix view
325-
list.AddRange(RecurseTabularRelationships(relOuter.ToColumn.Table, outerFactTable, bIsBusMatrix));
360+
list.AddRange(RecurseTabularRelationships(reportedDimensionColumn.Table, outerFactTable, bIsBusMatrix, listLatestRelationshipsTraversed, bThisRelationshipManyToMany));
326361
}
327362
}
328363

0 commit comments

Comments
 (0)