semantic-link-labs 0.12.8__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (243) hide show
  1. semantic_link_labs-0.12.8.dist-info/METADATA +354 -0
  2. semantic_link_labs-0.12.8.dist-info/RECORD +243 -0
  3. semantic_link_labs-0.12.8.dist-info/WHEEL +5 -0
  4. semantic_link_labs-0.12.8.dist-info/licenses/LICENSE +21 -0
  5. semantic_link_labs-0.12.8.dist-info/top_level.txt +1 -0
  6. sempy_labs/__init__.py +606 -0
  7. sempy_labs/_a_lib_info.py +2 -0
  8. sempy_labs/_ai.py +437 -0
  9. sempy_labs/_authentication.py +264 -0
  10. sempy_labs/_bpa_translation/_model/_translations_am-ET.po +869 -0
  11. sempy_labs/_bpa_translation/_model/_translations_ar-AE.po +908 -0
  12. sempy_labs/_bpa_translation/_model/_translations_bg-BG.po +968 -0
  13. sempy_labs/_bpa_translation/_model/_translations_ca-ES.po +963 -0
  14. sempy_labs/_bpa_translation/_model/_translations_cs-CZ.po +943 -0
  15. sempy_labs/_bpa_translation/_model/_translations_da-DK.po +945 -0
  16. sempy_labs/_bpa_translation/_model/_translations_de-DE.po +988 -0
  17. sempy_labs/_bpa_translation/_model/_translations_el-GR.po +993 -0
  18. sempy_labs/_bpa_translation/_model/_translations_es-ES.po +971 -0
  19. sempy_labs/_bpa_translation/_model/_translations_fa-IR.po +933 -0
  20. sempy_labs/_bpa_translation/_model/_translations_fi-FI.po +942 -0
  21. sempy_labs/_bpa_translation/_model/_translations_fr-FR.po +994 -0
  22. sempy_labs/_bpa_translation/_model/_translations_ga-IE.po +967 -0
  23. sempy_labs/_bpa_translation/_model/_translations_he-IL.po +902 -0
  24. sempy_labs/_bpa_translation/_model/_translations_hi-IN.po +944 -0
  25. sempy_labs/_bpa_translation/_model/_translations_hu-HU.po +963 -0
  26. sempy_labs/_bpa_translation/_model/_translations_id-ID.po +946 -0
  27. sempy_labs/_bpa_translation/_model/_translations_is-IS.po +939 -0
  28. sempy_labs/_bpa_translation/_model/_translations_it-IT.po +986 -0
  29. sempy_labs/_bpa_translation/_model/_translations_ja-JP.po +846 -0
  30. sempy_labs/_bpa_translation/_model/_translations_ko-KR.po +839 -0
  31. sempy_labs/_bpa_translation/_model/_translations_mt-MT.po +967 -0
  32. sempy_labs/_bpa_translation/_model/_translations_nl-NL.po +978 -0
  33. sempy_labs/_bpa_translation/_model/_translations_pl-PL.po +962 -0
  34. sempy_labs/_bpa_translation/_model/_translations_pt-BR.po +962 -0
  35. sempy_labs/_bpa_translation/_model/_translations_pt-PT.po +957 -0
  36. sempy_labs/_bpa_translation/_model/_translations_ro-RO.po +968 -0
  37. sempy_labs/_bpa_translation/_model/_translations_ru-RU.po +964 -0
  38. sempy_labs/_bpa_translation/_model/_translations_sk-SK.po +952 -0
  39. sempy_labs/_bpa_translation/_model/_translations_sl-SL.po +950 -0
  40. sempy_labs/_bpa_translation/_model/_translations_sv-SE.po +942 -0
  41. sempy_labs/_bpa_translation/_model/_translations_ta-IN.po +976 -0
  42. sempy_labs/_bpa_translation/_model/_translations_te-IN.po +947 -0
  43. sempy_labs/_bpa_translation/_model/_translations_th-TH.po +924 -0
  44. sempy_labs/_bpa_translation/_model/_translations_tr-TR.po +953 -0
  45. sempy_labs/_bpa_translation/_model/_translations_uk-UA.po +961 -0
  46. sempy_labs/_bpa_translation/_model/_translations_zh-CN.po +804 -0
  47. sempy_labs/_bpa_translation/_model/_translations_zu-ZA.po +969 -0
  48. sempy_labs/_capacities.py +1198 -0
  49. sempy_labs/_capacity_migration.py +660 -0
  50. sempy_labs/_clear_cache.py +351 -0
  51. sempy_labs/_connections.py +610 -0
  52. sempy_labs/_dashboards.py +69 -0
  53. sempy_labs/_data_access_security.py +98 -0
  54. sempy_labs/_data_pipelines.py +162 -0
  55. sempy_labs/_dataflows.py +668 -0
  56. sempy_labs/_dax.py +501 -0
  57. sempy_labs/_daxformatter.py +80 -0
  58. sempy_labs/_delta_analyzer.py +467 -0
  59. sempy_labs/_delta_analyzer_history.py +301 -0
  60. sempy_labs/_dictionary_diffs.py +221 -0
  61. sempy_labs/_documentation.py +147 -0
  62. sempy_labs/_domains.py +51 -0
  63. sempy_labs/_eventhouses.py +182 -0
  64. sempy_labs/_external_data_shares.py +230 -0
  65. sempy_labs/_gateways.py +521 -0
  66. sempy_labs/_generate_semantic_model.py +521 -0
  67. sempy_labs/_get_connection_string.py +84 -0
  68. sempy_labs/_git.py +543 -0
  69. sempy_labs/_graphQL.py +90 -0
  70. sempy_labs/_helper_functions.py +2833 -0
  71. sempy_labs/_icons.py +149 -0
  72. sempy_labs/_job_scheduler.py +609 -0
  73. sempy_labs/_kql_databases.py +149 -0
  74. sempy_labs/_kql_querysets.py +124 -0
  75. sempy_labs/_kusto.py +137 -0
  76. sempy_labs/_labels.py +124 -0
  77. sempy_labs/_list_functions.py +1720 -0
  78. sempy_labs/_managed_private_endpoints.py +253 -0
  79. sempy_labs/_mirrored_databases.py +416 -0
  80. sempy_labs/_mirrored_warehouses.py +60 -0
  81. sempy_labs/_ml_experiments.py +113 -0
  82. sempy_labs/_model_auto_build.py +140 -0
  83. sempy_labs/_model_bpa.py +557 -0
  84. sempy_labs/_model_bpa_bulk.py +378 -0
  85. sempy_labs/_model_bpa_rules.py +859 -0
  86. sempy_labs/_model_dependencies.py +343 -0
  87. sempy_labs/_mounted_data_factories.py +123 -0
  88. sempy_labs/_notebooks.py +441 -0
  89. sempy_labs/_one_lake_integration.py +151 -0
  90. sempy_labs/_onelake.py +131 -0
  91. sempy_labs/_query_scale_out.py +433 -0
  92. sempy_labs/_refresh_semantic_model.py +435 -0
  93. sempy_labs/_semantic_models.py +468 -0
  94. sempy_labs/_spark.py +455 -0
  95. sempy_labs/_sql.py +241 -0
  96. sempy_labs/_sql_audit_settings.py +207 -0
  97. sempy_labs/_sql_endpoints.py +214 -0
  98. sempy_labs/_tags.py +201 -0
  99. sempy_labs/_translations.py +43 -0
  100. sempy_labs/_user_delegation_key.py +44 -0
  101. sempy_labs/_utils.py +79 -0
  102. sempy_labs/_vertipaq.py +1021 -0
  103. sempy_labs/_vpax.py +388 -0
  104. sempy_labs/_warehouses.py +234 -0
  105. sempy_labs/_workloads.py +140 -0
  106. sempy_labs/_workspace_identity.py +72 -0
  107. sempy_labs/_workspaces.py +595 -0
  108. sempy_labs/admin/__init__.py +170 -0
  109. sempy_labs/admin/_activities.py +167 -0
  110. sempy_labs/admin/_apps.py +145 -0
  111. sempy_labs/admin/_artifacts.py +65 -0
  112. sempy_labs/admin/_basic_functions.py +463 -0
  113. sempy_labs/admin/_capacities.py +508 -0
  114. sempy_labs/admin/_dataflows.py +45 -0
  115. sempy_labs/admin/_datasets.py +186 -0
  116. sempy_labs/admin/_domains.py +522 -0
  117. sempy_labs/admin/_external_data_share.py +100 -0
  118. sempy_labs/admin/_git.py +72 -0
  119. sempy_labs/admin/_items.py +265 -0
  120. sempy_labs/admin/_labels.py +211 -0
  121. sempy_labs/admin/_reports.py +241 -0
  122. sempy_labs/admin/_scanner.py +118 -0
  123. sempy_labs/admin/_shared.py +82 -0
  124. sempy_labs/admin/_sharing_links.py +110 -0
  125. sempy_labs/admin/_tags.py +131 -0
  126. sempy_labs/admin/_tenant.py +503 -0
  127. sempy_labs/admin/_tenant_keys.py +89 -0
  128. sempy_labs/admin/_users.py +140 -0
  129. sempy_labs/admin/_workspaces.py +236 -0
  130. sempy_labs/deployment_pipeline/__init__.py +23 -0
  131. sempy_labs/deployment_pipeline/_items.py +580 -0
  132. sempy_labs/directlake/__init__.py +57 -0
  133. sempy_labs/directlake/_autosync.py +58 -0
  134. sempy_labs/directlake/_directlake_schema_compare.py +120 -0
  135. sempy_labs/directlake/_directlake_schema_sync.py +161 -0
  136. sempy_labs/directlake/_dl_helper.py +274 -0
  137. sempy_labs/directlake/_generate_shared_expression.py +94 -0
  138. sempy_labs/directlake/_get_directlake_lakehouse.py +62 -0
  139. sempy_labs/directlake/_get_shared_expression.py +34 -0
  140. sempy_labs/directlake/_guardrails.py +96 -0
  141. sempy_labs/directlake/_list_directlake_model_calc_tables.py +70 -0
  142. sempy_labs/directlake/_show_unsupported_directlake_objects.py +90 -0
  143. sempy_labs/directlake/_update_directlake_model_lakehouse_connection.py +239 -0
  144. sempy_labs/directlake/_update_directlake_partition_entity.py +259 -0
  145. sempy_labs/directlake/_warm_cache.py +236 -0
  146. sempy_labs/dotnet_lib/dotnet.runtime.config.json +10 -0
  147. sempy_labs/environment/__init__.py +23 -0
  148. sempy_labs/environment/_items.py +212 -0
  149. sempy_labs/environment/_pubstage.py +223 -0
  150. sempy_labs/eventstream/__init__.py +37 -0
  151. sempy_labs/eventstream/_items.py +263 -0
  152. sempy_labs/eventstream/_topology.py +652 -0
  153. sempy_labs/graph/__init__.py +59 -0
  154. sempy_labs/graph/_groups.py +651 -0
  155. sempy_labs/graph/_sensitivity_labels.py +120 -0
  156. sempy_labs/graph/_teams.py +125 -0
  157. sempy_labs/graph/_user_licenses.py +96 -0
  158. sempy_labs/graph/_users.py +516 -0
  159. sempy_labs/graph_model/__init__.py +15 -0
  160. sempy_labs/graph_model/_background_jobs.py +63 -0
  161. sempy_labs/graph_model/_items.py +149 -0
  162. sempy_labs/lakehouse/__init__.py +67 -0
  163. sempy_labs/lakehouse/_blobs.py +247 -0
  164. sempy_labs/lakehouse/_get_lakehouse_columns.py +102 -0
  165. sempy_labs/lakehouse/_get_lakehouse_tables.py +274 -0
  166. sempy_labs/lakehouse/_helper.py +250 -0
  167. sempy_labs/lakehouse/_lakehouse.py +351 -0
  168. sempy_labs/lakehouse/_livy_sessions.py +143 -0
  169. sempy_labs/lakehouse/_materialized_lake_views.py +157 -0
  170. sempy_labs/lakehouse/_partitioning.py +165 -0
  171. sempy_labs/lakehouse/_schemas.py +217 -0
  172. sempy_labs/lakehouse/_shortcuts.py +440 -0
  173. sempy_labs/migration/__init__.py +35 -0
  174. sempy_labs/migration/_create_pqt_file.py +238 -0
  175. sempy_labs/migration/_direct_lake_to_import.py +105 -0
  176. sempy_labs/migration/_migrate_calctables_to_lakehouse.py +398 -0
  177. sempy_labs/migration/_migrate_calctables_to_semantic_model.py +148 -0
  178. sempy_labs/migration/_migrate_model_objects_to_semantic_model.py +533 -0
  179. sempy_labs/migration/_migrate_tables_columns_to_semantic_model.py +172 -0
  180. sempy_labs/migration/_migration_validation.py +71 -0
  181. sempy_labs/migration/_refresh_calc_tables.py +131 -0
  182. sempy_labs/mirrored_azure_databricks_catalog/__init__.py +15 -0
  183. sempy_labs/mirrored_azure_databricks_catalog/_discover.py +213 -0
  184. sempy_labs/mirrored_azure_databricks_catalog/_refresh_catalog_metadata.py +45 -0
  185. sempy_labs/ml_model/__init__.py +23 -0
  186. sempy_labs/ml_model/_functions.py +427 -0
  187. sempy_labs/report/_BPAReportTemplate.json +232 -0
  188. sempy_labs/report/__init__.py +55 -0
  189. sempy_labs/report/_bpareporttemplate/.pbi/localSettings.json +9 -0
  190. sempy_labs/report/_bpareporttemplate/.platform +11 -0
  191. sempy_labs/report/_bpareporttemplate/StaticResources/SharedResources/BaseThemes/CY24SU06.json +710 -0
  192. sempy_labs/report/_bpareporttemplate/definition/pages/01d72098bda5055bd500/page.json +11 -0
  193. sempy_labs/report/_bpareporttemplate/definition/pages/01d72098bda5055bd500/visuals/1b08bce3bebabb0a27a8/visual.json +191 -0
  194. sempy_labs/report/_bpareporttemplate/definition/pages/01d72098bda5055bd500/visuals/2f22ddb70c301693c165/visual.json +438 -0
  195. sempy_labs/report/_bpareporttemplate/definition/pages/01d72098bda5055bd500/visuals/3b1182230aa6c600b43a/visual.json +127 -0
  196. sempy_labs/report/_bpareporttemplate/definition/pages/01d72098bda5055bd500/visuals/58577ba6380c69891500/visual.json +576 -0
  197. sempy_labs/report/_bpareporttemplate/definition/pages/01d72098bda5055bd500/visuals/a2a8fa5028b3b776c96c/visual.json +207 -0
  198. sempy_labs/report/_bpareporttemplate/definition/pages/01d72098bda5055bd500/visuals/adfd47ef30652707b987/visual.json +506 -0
  199. sempy_labs/report/_bpareporttemplate/definition/pages/01d72098bda5055bd500/visuals/b6a80ee459e716e170b1/visual.json +127 -0
  200. sempy_labs/report/_bpareporttemplate/definition/pages/01d72098bda5055bd500/visuals/ce3130a721c020cc3d81/visual.json +513 -0
  201. sempy_labs/report/_bpareporttemplate/definition/pages/92735ae19b31712208ad/page.json +8 -0
  202. sempy_labs/report/_bpareporttemplate/definition/pages/92735ae19b31712208ad/visuals/66e60dfb526437cd78d1/visual.json +112 -0
  203. sempy_labs/report/_bpareporttemplate/definition/pages/c597da16dc7e63222a82/page.json +11 -0
  204. sempy_labs/report/_bpareporttemplate/definition/pages/c597da16dc7e63222a82/visuals/07deb8bce824e1be37d7/visual.json +513 -0
  205. sempy_labs/report/_bpareporttemplate/definition/pages/c597da16dc7e63222a82/visuals/0b1c68838818b32ad03b/visual.json +352 -0
  206. sempy_labs/report/_bpareporttemplate/definition/pages/c597da16dc7e63222a82/visuals/0c171de9d2683d10b930/visual.json +37 -0
  207. sempy_labs/report/_bpareporttemplate/definition/pages/c597da16dc7e63222a82/visuals/0efa01be0510e40a645e/visual.json +542 -0
  208. sempy_labs/report/_bpareporttemplate/definition/pages/c597da16dc7e63222a82/visuals/6bf2f0eb830ab53cc668/visual.json +221 -0
  209. sempy_labs/report/_bpareporttemplate/definition/pages/c597da16dc7e63222a82/visuals/88d8141cb8500b60030c/visual.json +127 -0
  210. sempy_labs/report/_bpareporttemplate/definition/pages/c597da16dc7e63222a82/visuals/a753273590beed656a03/visual.json +576 -0
  211. sempy_labs/report/_bpareporttemplate/definition/pages/c597da16dc7e63222a82/visuals/b8fdc82cddd61ac447bc/visual.json +127 -0
  212. sempy_labs/report/_bpareporttemplate/definition/pages/d37dce724a0ccc30044b/page.json +9 -0
  213. sempy_labs/report/_bpareporttemplate/definition/pages/d37dce724a0ccc30044b/visuals/ce8532a7e25020271077/visual.json +38 -0
  214. sempy_labs/report/_bpareporttemplate/definition/pages/pages.json +10 -0
  215. sempy_labs/report/_bpareporttemplate/definition/report.json +176 -0
  216. sempy_labs/report/_bpareporttemplate/definition/version.json +4 -0
  217. sempy_labs/report/_bpareporttemplate/definition.pbir +14 -0
  218. sempy_labs/report/_download_report.py +76 -0
  219. sempy_labs/report/_export_report.py +257 -0
  220. sempy_labs/report/_generate_report.py +427 -0
  221. sempy_labs/report/_paginated.py +76 -0
  222. sempy_labs/report/_report_bpa.py +354 -0
  223. sempy_labs/report/_report_bpa_rules.py +115 -0
  224. sempy_labs/report/_report_functions.py +581 -0
  225. sempy_labs/report/_report_helper.py +227 -0
  226. sempy_labs/report/_report_list_functions.py +110 -0
  227. sempy_labs/report/_report_rebind.py +149 -0
  228. sempy_labs/report/_reportwrapper.py +3100 -0
  229. sempy_labs/report/_save_report.py +147 -0
  230. sempy_labs/snowflake_database/__init__.py +10 -0
  231. sempy_labs/snowflake_database/_items.py +105 -0
  232. sempy_labs/sql_database/__init__.py +21 -0
  233. sempy_labs/sql_database/_items.py +201 -0
  234. sempy_labs/sql_database/_mirroring.py +79 -0
  235. sempy_labs/theme/__init__.py +12 -0
  236. sempy_labs/theme/_org_themes.py +129 -0
  237. sempy_labs/tom/__init__.py +3 -0
  238. sempy_labs/tom/_model.py +5977 -0
  239. sempy_labs/variable_library/__init__.py +19 -0
  240. sempy_labs/variable_library/_functions.py +403 -0
  241. sempy_labs/warehouse/__init__.py +28 -0
  242. sempy_labs/warehouse/_items.py +234 -0
  243. sempy_labs/warehouse/_restore_points.py +309 -0
@@ -0,0 +1,859 @@
1
+ import sempy
2
+ import pandas as pd
3
+ import re
4
+ from typing import Optional
5
+ from sempy._utils._log import log
6
+
7
+
8
+ @log
9
+ def model_bpa_rules(
10
+ dependencies: Optional[pd.DataFrame] = None,
11
+ **kwargs,
12
+ ) -> pd.DataFrame:
13
+ """
14
+ Shows the default rules for the semantic model BPA used by the run_model_bpa function.
15
+
16
+ Parameters
17
+ ----------
18
+ dependencies : pd.DataFrame, default=None
19
+ A pandas dataframe with the output of the 'get_model_calc_dependencies' function.
20
+
21
+ Returns
22
+ -------
23
+ pandas.DataFrame
24
+ A pandas dataframe containing the default rules for the run_model_bpa function.
25
+ """
26
+
27
+ sempy.fabric._client._utils._init_analysis_services()
28
+ import Microsoft.AnalysisServices.Tabular as TOM
29
+
30
+ if "dataset" in kwargs:
31
+ print(
32
+ "The 'dataset' parameter has been deprecated. Please remove this parameter from the function going forward."
33
+ )
34
+ del kwargs["dataset"]
35
+ if "workspace" in kwargs:
36
+ print(
37
+ "The 'workspace' parameter has been deprecated. Please remove this parameter from the function going forward."
38
+ )
39
+ del kwargs["workspace"]
40
+
41
+ rules = pd.DataFrame(
42
+ [
43
+ (
44
+ "Performance",
45
+ "Column",
46
+ "Warning",
47
+ "Do not use floating point data types",
48
+ lambda obj, tom: obj.DataType == TOM.DataType.Double,
49
+ 'The "Double" floating point data type should be avoided, as it can result in unpredictable roundoff errors and decreased performance in certain scenarios. Use "Int64" or "Decimal" where appropriate (but note that "Decimal" is limited to 4 digits after the decimal sign).',
50
+ ),
51
+ (
52
+ "Performance",
53
+ "Column",
54
+ "Warning",
55
+ "Avoid using calculated columns",
56
+ lambda obj, tom: obj.Type == TOM.ColumnType.Calculated,
57
+ "Calculated columns do not compress as well as data columns so they take up more memory. They also slow down processing times for both the table as well as process recalc. Offload calculated column logic to your data warehouse and turn these calculated columns into data columns.",
58
+ "https://www.elegantbi.com/post/top10bestpractices",
59
+ ),
60
+ (
61
+ "Performance",
62
+ "Relationship",
63
+ "Warning",
64
+ "Check if bi-directional and many-to-many relationships are valid",
65
+ lambda obj, tom: (
66
+ obj.FromCardinality == TOM.RelationshipEndCardinality.Many
67
+ and obj.ToCardinality == TOM.RelationshipEndCardinality.Many
68
+ )
69
+ or str(obj.CrossFilteringBehavior) == "BothDirections",
70
+ "Bi-directional and many-to-many relationships may cause performance degradation or even have unintended consequences. Make sure to check these specific relationships to ensure they are working as designed and are actually necessary.",
71
+ "https://www.sqlbi.com/articles/bidirectional-relationships-and-ambiguity-in-dax",
72
+ ),
73
+ (
74
+ "Performance",
75
+ "Row Level Security",
76
+ "Info",
77
+ "Check if dynamic row level security (RLS) is necessary",
78
+ lambda obj, tom: any(
79
+ re.search(pattern, obj.FilterExpression, flags=re.IGNORECASE)
80
+ for pattern in ["USERPRINCIPALNAME()", "USERNAME()"]
81
+ ),
82
+ "Usage of dynamic row level security (RLS) can add memory and performance overhead. Please research the pros/cons of using it.",
83
+ "https://docs.microsoft.com/power-bi/admin/service-admin-rls",
84
+ ),
85
+ (
86
+ "Performance",
87
+ "Table",
88
+ "Warning",
89
+ "Avoid using many-to-many relationships on tables used for dynamic row level security",
90
+ lambda obj, tom: any(
91
+ r.FromCardinality == TOM.RelationshipEndCardinality.Many
92
+ and r.ToCardinality == TOM.RelationshipEndCardinality.Many
93
+ for r in tom.used_in_relationships(object=obj)
94
+ )
95
+ and any(t.Name == obj.Name for t in tom.all_rls()),
96
+ "Using many-to-many relationships on tables which use dynamic row level security can cause serious query performance degradation. This pattern's performance problems compound when snowflaking multiple many-to-many relationships against a table which contains row level security. Instead, use one of the patterns shown in the article below where a single dimension table relates many-to-one to a security table.",
97
+ "https://www.elegantbi.com/post/dynamicrlspatterns",
98
+ ),
99
+ (
100
+ "Performance",
101
+ "Relationship",
102
+ "Warning",
103
+ "Many-to-many relationships should be single-direction",
104
+ lambda obj, tom: (
105
+ obj.FromCardinality == TOM.RelationshipEndCardinality.Many
106
+ and obj.ToCardinality == TOM.RelationshipEndCardinality.Many
107
+ )
108
+ and obj.CrossFilteringBehavior
109
+ == TOM.CrossFilteringBehavior.BothDirections,
110
+ ),
111
+ (
112
+ "Performance",
113
+ "Column",
114
+ "Warning",
115
+ "Set IsAvailableInMdx to false on non-attribute columns",
116
+ lambda obj, tom: tom.is_direct_lake() is False
117
+ and obj.IsAvailableInMDX
118
+ and (obj.IsHidden or obj.Parent.IsHidden)
119
+ and obj.SortByColumn is None
120
+ and not any(tom.used_in_sort_by(column=obj))
121
+ and not any(tom.used_in_hierarchies(column=obj)),
122
+ "To speed up processing time and conserve memory after processing, attribute hierarchies should not be built for columns that are never used for slicing by MDX clients. In other words, all hidden columns that are not used as a Sort By Column or referenced in user hierarchies should have their IsAvailableInMdx property set to false. The IsAvailableInMdx property is not relevant for Direct Lake models.",
123
+ "https://blog.crossjoin.co.uk/2018/07/02/isavailableinmdx-ssas-tabular",
124
+ ),
125
+ (
126
+ "Performance",
127
+ "Partition",
128
+ "Warning",
129
+ "Set 'Data Coverage Definition' property on the DirectQuery partition of a hybrid table",
130
+ lambda obj, tom: tom.is_hybrid_table(table_name=obj.Parent.Name)
131
+ and obj.Mode == TOM.ModeType.DirectQuery
132
+ and obj.DataCoverageDefinition is None,
133
+ "Setting the 'Data Coverage Definition' property may lead to better performance because the engine knows when it can only query the import-portion of the table and when it needs to query the DirectQuery portion of the table.",
134
+ "https://learn.microsoft.com/analysis-services/tom/table-partitions?view=asallproducts-allversions",
135
+ ),
136
+ (
137
+ "Performance",
138
+ "Model",
139
+ "Warning",
140
+ "Dual mode is only relevant for dimension tables if DirectQuery is used for the corresponding fact table",
141
+ lambda obj, tom: not any(
142
+ p.Mode == TOM.ModeType.DirectQuery for p in tom.all_partitions()
143
+ )
144
+ and any(p.Mode == TOM.ModeType.Dual for p in tom.all_partitions()),
145
+ "Only use Dual mode for dimension tables/partitions where a corresponding fact table is in DirectQuery. Using Dual mode in other circumstances (i.e. rest of the model is in Import mode) may lead to performance issues especially if the number of measures in the model is high.",
146
+ ),
147
+ (
148
+ "Performance",
149
+ "Table",
150
+ "Warning",
151
+ "Set dimensions tables to dual mode instead of import when using DirectQuery on fact tables",
152
+ lambda obj, tom: sum(
153
+ 1 for p in obj.Partitions if p.Mode == TOM.ModeType.Import
154
+ )
155
+ == 1
156
+ and obj.Partitions.Count == 1
157
+ and tom.has_hybrid_table()
158
+ and any(
159
+ r.ToCardinality == TOM.RelationshipEndCardinality.One
160
+ and r.ToTable.Name == obj.Name
161
+ for r in tom.used_in_relationships(object=obj)
162
+ ),
163
+ "When using DirectQuery, dimension tables should be set to Dual mode in order to improve query performance.",
164
+ "https://learn.microsoft.com/power-bi/transform-model/desktop-storage-mode#propagation-of-the-dual-setting",
165
+ ),
166
+ (
167
+ "Performance",
168
+ "Partition",
169
+ "Warning",
170
+ "Minimize Power Query transformations",
171
+ lambda obj, tom: obj.SourceType == TOM.PartitionSourceType.M
172
+ and any(
173
+ item in obj.Source.Expression
174
+ for item in [
175
+ 'Table.Combine("',
176
+ 'Table.Join("',
177
+ 'Table.NestedJoin("',
178
+ 'Table.AddColumn("',
179
+ 'Table.Group("',
180
+ 'Table.Sort("',
181
+ 'Table.Pivot("',
182
+ 'Table.Unpivot("',
183
+ 'Table.UnpivotOtherColumns("',
184
+ 'Table.Distinct("',
185
+ '[Query=(""SELECT',
186
+ "Value.NativeQuery",
187
+ "OleDb.Query",
188
+ "Odbc.Query",
189
+ ]
190
+ ),
191
+ "Minimize Power Query transformations in order to improve model processing performance. It is a best practice to offload these transformations to the data warehouse if possible. Also, please check whether query folding is occurring within your model. Please reference the article below for more information on query folding.",
192
+ "https://docs.microsoft.com/power-query/power-query-folding",
193
+ ),
194
+ (
195
+ "Performance",
196
+ "Table",
197
+ "Warning",
198
+ "Consider a star-schema instead of a snowflake architecture",
199
+ lambda obj, tom: obj.CalculationGroup is None
200
+ and (
201
+ any(
202
+ r.FromTable.Name == obj.Name
203
+ for r in tom.used_in_relationships(object=obj)
204
+ )
205
+ and any(
206
+ r.ToTable.Name == obj.Name
207
+ for r in tom.used_in_relationships(object=obj)
208
+ )
209
+ ),
210
+ "Generally speaking, a star-schema is the optimal architecture for tabular models. That being the case, there are valid cases to use a snowflake approach. Please check your model and consider moving to a star-schema architecture.",
211
+ "https://docs.microsoft.com/power-bi/guidance/star-schema",
212
+ ),
213
+ (
214
+ "Performance",
215
+ "Model",
216
+ "Warning",
217
+ "Avoid using views when using Direct Lake mode",
218
+ lambda obj, tom: tom.is_direct_lake_using_view(),
219
+ "In Direct Lake mode, views will always fall back to DirectQuery. Thus, in order to obtain the best performance use lakehouse tables instead of views.",
220
+ "https://learn.microsoft.com/fabric/get-started/direct-lake-overview#fallback",
221
+ ),
222
+ (
223
+ "Performance",
224
+ "Measure",
225
+ "Warning",
226
+ "Avoid adding 0 to a measure",
227
+ lambda obj, tom: obj.Expression.replace(" ", "").startswith("0+")
228
+ or obj.Expression.replace(" ", "").endswith("+0")
229
+ or re.search(
230
+ r"DIVIDE\s*\(\s*[^,]+,\s*[^,]+,\s*0\s*\)",
231
+ obj.Expression,
232
+ flags=re.IGNORECASE,
233
+ )
234
+ or re.search(
235
+ r"IFERROR\s*\(\s*[^,]+,\s*0\s*\)",
236
+ obj.Expression,
237
+ flags=re.IGNORECASE,
238
+ ),
239
+ "Adding 0 to a measure in order for it not to show a blank value may negatively impact performance.",
240
+ ),
241
+ (
242
+ "Performance",
243
+ "Table",
244
+ "Warning",
245
+ "Reduce usage of calculated tables",
246
+ lambda obj, tom: tom.is_field_parameter(table_name=obj.Name) is False
247
+ and tom.is_calculated_table(table_name=obj.Name),
248
+ "Migrate calculated table logic to your data warehouse. Reliance on calculated tables will lead to technical debt and potential misalignments if you have multiple models on your platform.",
249
+ ),
250
+ (
251
+ "Performance",
252
+ "Column",
253
+ "Warning",
254
+ "Reduce usage of calculated columns that use the RELATED function",
255
+ lambda obj, tom: obj.Type == TOM.ColumnType.Calculated
256
+ and re.search(r"related\s*\(", obj.Expression, flags=re.IGNORECASE),
257
+ "Calculated columns do not compress as well as data columns and may cause longer processing times. As such, calculated columns should be avoided if possible. One scenario where they may be easier to avoid is if they use the RELATED function.",
258
+ "https://www.sqlbi.com/articles/storage-differences-between-calculated-columns-and-calculated-tables",
259
+ ),
260
+ (
261
+ "Performance",
262
+ "Model",
263
+ "Warning",
264
+ "Avoid excessive bi-directional or many-to-many relationships",
265
+ lambda obj, tom: (
266
+ (
267
+ sum(
268
+ 1
269
+ for r in obj.Relationships
270
+ if r.CrossFilteringBehavior
271
+ == TOM.CrossFilteringBehavior.BothDirections
272
+ )
273
+ + sum(
274
+ 1
275
+ for r in obj.Relationships
276
+ if (
277
+ r.FromCardinality == TOM.RelationshipEndCardinality.Many
278
+ )
279
+ and (r.ToCardinality == TOM.RelationshipEndCardinality.Many)
280
+ )
281
+ )
282
+ / max(int(obj.Relationships.Count), 1)
283
+ )
284
+ > 0.3,
285
+ "Limit use of b-di and many-to-many relationships. This rule flags the model if more than 30% of relationships are bi-di or many-to-many.",
286
+ "https://www.sqlbi.com/articles/bidirectional-relationships-and-ambiguity-in-dax",
287
+ ),
288
+ # ('Performance', 'Column', 'Warning', 'Avoid bi-directional or many-to-many relationships against high-cardinality columns',
289
+ # lambda obj, tom: ((str(r.FromCardinality) == 'Many' and str(r.ToCardinality == 'Many')) or (str(r.CrossFilteringBehavior) == 'BothDirections') for r in tom.used_in_relationships(object = obj)) and tom.cardinality(column = obj) > 100000,
290
+ # 'For best performance, it is recommended to avoid using bi-directional relationships against high-cardinality columns',
291
+ # ),
292
+ (
293
+ "Performance",
294
+ "Table",
295
+ "Warning",
296
+ "Remove auto-date table",
297
+ lambda obj, tom: tom.is_calculated_table(table_name=obj.Name)
298
+ and (
299
+ obj.Name.startswith("DateTableTemplate_")
300
+ or obj.Name.startswith("LocalDateTable_")
301
+ ),
302
+ "Avoid using auto-date tables. Make sure to turn off auto-date table in the settings in Power BI Desktop. This will save memory resources.",
303
+ "https://www.youtube.com/watch?v=xu3uDEHtCrg",
304
+ ),
305
+ (
306
+ "Performance",
307
+ "Table",
308
+ "Warning",
309
+ "Date/calendar tables should be marked as a date table",
310
+ lambda obj, tom: (
311
+ re.search(r"date", obj.Name, flags=re.IGNORECASE)
312
+ or re.search(r"calendar", obj.Name, flags=re.IGNORECASE)
313
+ )
314
+ and str(obj.DataCategory) != "Time",
315
+ "This rule looks for tables that contain the words 'date' or 'calendar' as they should likely be marked as a date table.",
316
+ "https://docs.microsoft.com/power-bi/transform-model/desktop-date-tables",
317
+ ),
318
+ (
319
+ "Performance",
320
+ "Table",
321
+ "Warning",
322
+ "Large tables should be partitioned",
323
+ lambda obj, tom: tom.is_direct_lake() is False
324
+ and int(obj.Partitions.Count) == 1
325
+ and tom.row_count(object=obj) > 25000000,
326
+ "Large tables should be partitioned in order to optimize processing. This is not relevant for semantic models in Direct Lake mode as they can only have one partition per table.",
327
+ ),
328
+ (
329
+ "Performance",
330
+ "Row Level Security",
331
+ "Warning",
332
+ "Limit row level security (RLS) logic",
333
+ lambda obj, tom: any(
334
+ item in obj.FilterExpression.lower()
335
+ for item in [
336
+ "right(",
337
+ "left(",
338
+ "filter(",
339
+ "upper(",
340
+ "lower(",
341
+ "find(",
342
+ ]
343
+ ),
344
+ "Try to simplify the DAX used for row level security. Usage of the functions within this rule can likely be offloaded to the upstream systems (data warehouse).",
345
+ ),
346
+ (
347
+ "Performance",
348
+ "Model",
349
+ "Warning",
350
+ "Model should have a date table",
351
+ lambda obj, tom: not any(
352
+ (c.IsKey and c.DataType == TOM.DataType.DateTime)
353
+ and str(t.DataCategory) == "Time"
354
+ for t in obj.Tables
355
+ for c in t.Columns
356
+ ),
357
+ "Generally speaking, models should generally have a date table. Models that do not have a date table generally are not taking advantage of features such as time intelligence or may not have a properly structured architecture.",
358
+ ),
359
+ # ('Performance', 'Measure', 'Warning', 'Measures using time intelligence and model is using Direct Query',
360
+ # lambda obj, tom: any(str(p.Mode) == 'DirectQuery' for p in tom.all_partitions()) and any(re.search(pattern + '\s*\(', obj.Expression, flags=re.IGNORECASE) for pattern in ['CLOSINGBALANCEMONTH', 'CLOSINGBALANCEQUARTER', 'CLOSINGBALANCEYEAR', \
361
+ # 'DATEADD', 'DATESBETWEEN', 'DATESINPERIOD', 'DATESMTD', 'DATESQTD', 'DATESYTD', 'ENDOFMONTH', 'ENDOFQUARTER', 'ENDOFYEAR', 'FIRSTDATE', 'FIRSTNONBLANK', 'FIRSTNONBLANKVALUE', 'LASTDATE', 'LASTNONBLANK', 'LASTNONBLANKVALUE', \
362
+ # 'NEXTDAY', 'NEXTMONTH', 'NEXTQUARTER', 'NEXTYEAR', 'OPENINGBALANCEMONTH', 'OPENINGBALANCEQUARTER', 'OPENINGBALANCEYEAR', 'PARALLELPERIOD', 'PREVIOUSDAY', 'PREVIOUSMONTH', 'PREVIOUSQUARTER', 'PREVIOUSYEAR', 'SAMEPERIODLASTYEAR', \
363
+ # 'STARTOFMONTH', 'STARTOFQUARTER', 'STARTOFYEAR', 'TOTALMTD', 'TOTALQTD', 'TOTALYTD']),
364
+ # 'At present, time intelligence functions are known to not perform as well when using Direct Query. If you are having performance issues, you may want to try alternative solutions such as adding columns in the fact table that show previous year or previous month data.',
365
+ # ),
366
+ (
367
+ "Error Prevention",
368
+ "Calculation Item",
369
+ "Error",
370
+ "Calculation items must have an expression",
371
+ lambda obj, tom: len(obj.Expression) == 0,
372
+ "Calculation items must have an expression. Without an expression, they will not show any values.",
373
+ ),
374
+ # ('Error Prevention', ['Table', 'Column', 'Measure', 'Hierarchy', 'Partition'], 'Error', 'Avoid invalid characters in names',
375
+ # lambda obj, tom: obj.Name
376
+ # 'This rule identifies if a name for a given object in your model (i.e. table/column/measure) which contains an invalid character. Invalid characters will cause an error when deploying the model (and failure to deploy). This rule has a fix expression which converts the invalid character into a space, resolving the issue.',
377
+ # ),
378
+ # ('Error Prevention', ['Table', 'Column', 'Measure', 'Hierarchy'], 'Error', 'Avoid invalid characters in descriptions',
379
+ # lambda obj, tom: obj.Description
380
+ # 'This rule identifies if a description for a given object in your model (i.e. table/column/measure) which contains an invalid character. Invalid characters will cause an error when deploying the model (and failure to deploy). This rule has a fix expression which converts the invalid character into a space, resolving the issue.',
381
+ # ),
382
+ (
383
+ "Error Prevention",
384
+ "Relationship",
385
+ "Warning",
386
+ "Relationship columns should be of the same data type",
387
+ lambda obj, tom: obj.FromColumn.DataType != obj.ToColumn.DataType,
388
+ "Columns used in a relationship should be of the same data type. Ideally, they will be of integer data type (see the related rule '[Formatting] Relationship columns should be of integer data type'). Having columns within a relationship which are of different data types may lead to various issues.",
389
+ ),
390
+ (
391
+ "Error Prevention",
392
+ "Column",
393
+ "Error",
394
+ "Data columns must have a source column",
395
+ lambda obj, tom: obj.Type == TOM.ColumnType.Data
396
+ and len(obj.SourceColumn) == 0,
397
+ "Data columns must have a source column. A data column without a source column will cause an error when processing the model.",
398
+ ),
399
+ (
400
+ "Error Prevention",
401
+ "Column",
402
+ "Warning",
403
+ "Set IsAvailableInMdx to true on necessary columns",
404
+ lambda obj, tom: tom.is_direct_lake() is False
405
+ and obj.IsAvailableInMDX is False
406
+ and (
407
+ any(tom.used_in_sort_by(column=obj))
408
+ or any(tom.used_in_hierarchies(column=obj))
409
+ or obj.SortByColumn is not None
410
+ ),
411
+ "In order to avoid errors, ensure that attribute hierarchies are enabled if a column is used for sorting another column, used in a hierarchy, used in variations, or is sorted by another column. The IsAvailableInMdx property is not relevant for Direct Lake models.",
412
+ ),
413
+ (
414
+ "Error Prevention",
415
+ "Table",
416
+ "Error",
417
+ "Avoid the USERELATIONSHIP function and RLS against the same table",
418
+ lambda obj, tom: any(
419
+ re.search(
420
+ r"USERELATIONSHIP\s*\(\s*.+?(?=])\]\s*,\s*'*"
421
+ + re.escape(obj.Name)
422
+ + r"'*\[",
423
+ m.Expression,
424
+ flags=re.IGNORECASE,
425
+ )
426
+ for m in tom.all_measures()
427
+ )
428
+ and any(r.Table.Name == obj.Name for r in tom.all_rls()),
429
+ "The USERELATIONSHIP function may not be used against a table which also leverages row-level security (RLS). This will generate an error when using the particular measure in a visual. This rule will highlight the table which is used in a measure's USERELATIONSHIP function as well as RLS.",
430
+ "https://blog.crossjoin.co.uk/2013/05/10/userelationship-and-tabular-row-security",
431
+ ),
432
+ (
433
+ "DAX Expressions",
434
+ "Measure",
435
+ "Warning",
436
+ "Avoid using the IFERROR function",
437
+ lambda obj, tom: re.search(
438
+ r"iferror\s*\(", obj.Expression, flags=re.IGNORECASE
439
+ ),
440
+ "Avoid using the IFERROR function as it may cause performance degradation. If you are concerned about a divide-by-zero error, use the DIVIDE function as it naturally resolves such errors as blank (or you can customize what should be shown in case of such an error).",
441
+ "https://www.elegantbi.com/post/top10bestpractices",
442
+ ),
443
+ (
444
+ "DAX Expressions",
445
+ "Measure",
446
+ "Warning",
447
+ "Use the TREATAS function instead of INTERSECT for virtual relationships",
448
+ lambda obj, tom: re.search(
449
+ r"intersect\s*\(", obj.Expression, flags=re.IGNORECASE
450
+ ),
451
+ "The TREATAS function is more efficient and provides better performance than the INTERSECT function when used in virutal relationships.",
452
+ "https://www.sqlbi.com/articles/propagate-filters-using-treatas-in-dax",
453
+ ),
454
+ (
455
+ "DAX Expressions",
456
+ "Measure",
457
+ "Warning",
458
+ "The EVALUATEANDLOG function should not be used in production models",
459
+ lambda obj, tom: re.search(
460
+ r"evaluateandlog\s*\(",
461
+ obj.Expression,
462
+ flags=re.IGNORECASE,
463
+ ),
464
+ "The EVALUATEANDLOG function is meant to be used only in development/test environments and should not be used in production models.",
465
+ "https://pbidax.wordpress.com/2022/08/16/introduce-the-dax-evaluateandlog-function",
466
+ ),
467
+ (
468
+ "DAX Expressions",
469
+ "Measure",
470
+ "Warning",
471
+ "Measures should not be direct references of other measures",
472
+ lambda obj, tom: any(
473
+ obj.Expression == f"[{m.Name}]" for m in tom.all_measures()
474
+ ),
475
+ "This rule identifies measures which are simply a reference to another measure. As an example, consider a model with two measures: [MeasureA] and [MeasureB]. This rule would be triggered for MeasureB if MeasureB's DAX was MeasureB:=[MeasureA]. Such duplicative measures should be removed.",
476
+ ),
477
+ (
478
+ "DAX Expressions",
479
+ "Measure",
480
+ "Warning",
481
+ "No two measures should have the same definition",
482
+ lambda obj, tom: any(
483
+ re.sub(r"\s+", "", obj.Expression)
484
+ == re.sub(r"\s+", "", m.Expression)
485
+ and obj.Name != m.Name
486
+ for m in tom.all_measures()
487
+ ),
488
+ "Two measures with different names and defined by the same DAX expression should be avoided to reduce redundancy.",
489
+ ),
490
+ (
491
+ "DAX Expressions",
492
+ "Measure",
493
+ "Warning",
494
+ "Avoid addition or subtraction of constant values to results of divisions",
495
+ lambda obj, tom: re.search(
496
+ r"DIVIDE\s*\((\s*.*?)\)\s*[+-]\s*1|\/\s*.*(?=[-+]\s*1)",
497
+ obj.Expression,
498
+ flags=re.IGNORECASE,
499
+ ),
500
+ "Adding a constant value may lead to performance degradation.",
501
+ ),
502
+ (
503
+ "DAX Expressions",
504
+ "Measure",
505
+ "Warning",
506
+ "Avoid using '1-(x/y)' syntax",
507
+ lambda obj, tom: re.search(
508
+ r"[0-9]+\s*[-+]\s*[\(]*\s*SUM\s*\(\s*\'*[A-Za-z0-9 _]+\'*\s*\[[A-Za-z0-9 _]+\]\s*\)\s*/",
509
+ obj.Expression,
510
+ flags=re.IGNORECASE,
511
+ )
512
+ or re.search(
513
+ r"[0-9]+\s*[-+]\s*DIVIDE\s*\(",
514
+ obj.Expression,
515
+ flags=re.IGNORECASE,
516
+ ),
517
+ "Instead of using the '1-(x/y)' or '1+(x/y)' syntax to achieve a percentage calculation, use the basic DAX functions (as shown below). Using the improved syntax will generally improve the performance. The '1+/-...' syntax always returns a value whereas the solution without the '1+/-...' does not (as the value may be 'blank'). Therefore the '1+/-...' syntax may return more rows/columns which may result in a slower query speed. Let's clarify with an example: Avoid this: 1 - SUM ( 'Sales'[CostAmount] ) / SUM( 'Sales'[SalesAmount] ) Better: DIVIDE ( SUM ( 'Sales'[SalesAmount] ) - SUM ( 'Sales'[CostAmount] ), SUM ( 'Sales'[SalesAmount] ) ) Best: VAR x = SUM ( 'Sales'[SalesAmount] ) RETURN DIVIDE ( x - SUM ( 'Sales'[CostAmount] ), x )",
518
+ ),
519
+ (
520
+ "DAX Expressions",
521
+ "Measure",
522
+ "Warning",
523
+ "Filter measure values by columns, not tables",
524
+ lambda obj, tom: re.search(
525
+ r"CALCULATE\s*\(\s*[^,]+,\s*FILTER\s*\(\s*\'*[A-Za-z0-9 _]+\'*\s*,\s*\[[^\]]+\]",
526
+ obj.Expression,
527
+ flags=re.IGNORECASE,
528
+ )
529
+ or re.search(
530
+ r"CALCULATETABLE\s*\(\s*[^,]*,\s*FILTER\s*\(\s*\'*[A-Za-z0-9 _]+\'*\s*,\s*\[",
531
+ obj.Expression,
532
+ flags=re.IGNORECASE,
533
+ ),
534
+ "Instead of using this pattern FILTER('Table',[Measure]>Value) for the filter parameters of a CALCULATE or CALCULATETABLE function, use one of the options below (if possible). Filtering on a specific column will produce a smaller table for the engine to process, thereby enabling faster performance. Using the VALUES function or the ALL function depends on the desired measure result.\nOption 1: FILTER(VALUES('Table'[Column]),[Measure] > Value)\nOption 2: FILTER(ALL('Table'[Column]),[Measure] > Value)",
535
+ "https://docs.microsoft.com/power-bi/guidance/dax-avoid-avoid-filter-as-filter-argument",
536
+ ),
537
+ (
538
+ "DAX Expressions",
539
+ "Measure",
540
+ "Warning",
541
+ "Filter column values with proper syntax",
542
+ lambda obj, tom: re.search(
543
+ r"CALCULATE\s*\(\s*[^,]+,\s*FILTER\s*\(\s*'*[A-Za-z0-9 _]+'*\s*,\s*'*[A-Za-z0-9 _]+'*\[[A-Za-z0-9 _]+\]",
544
+ obj.Expression,
545
+ flags=re.IGNORECASE,
546
+ )
547
+ or re.search(
548
+ r"CALCULATETABLE\s*\([^,]*,\s*FILTER\s*\(\s*'*[A-Za-z0-9 _]+'*\s*,\s*'*[A-Za-z0-9 _]+'*\[[A-Za-z0-9 _]+\]",
549
+ obj.Expression,
550
+ flags=re.IGNORECASE,
551
+ ),
552
+ "Instead of using this pattern FILTER('Table','Table'[Column]=\"Value\") for the filter parameters of a CALCULATE or CALCULATETABLE function, use one of the options below. As far as whether to use the KEEPFILTERS function, see the second reference link below.\nOption 1: KEEPFILTERS('Table'[Column]=\"Value\")\nOption 2: 'Table'[Column]=\"Value\"",
553
+ "https://docs.microsoft.com/power-bi/guidance/dax-avoid-avoid-filter-as-filter-argument Reference: https://www.sqlbi.com/articles/using-keepfilters-in-dax",
554
+ ),
555
+ (
556
+ "DAX Expressions",
557
+ "Measure",
558
+ "Warning",
559
+ "Use the DIVIDE function for division",
560
+ lambda obj, tom: re.search(
561
+ r"\]\s*\/(?!\/)(?!\*)|\)\s*\/(?!\/)(?!\*)",
562
+ obj.Expression,
563
+ flags=re.IGNORECASE,
564
+ ),
565
+ 'Use the DIVIDE function instead of using "/". The DIVIDE function resolves divide-by-zero cases. As such, it is recommended to use to avoid errors.',
566
+ "https://docs.microsoft.com/power-bi/guidance/dax-divide-function-operator",
567
+ ),
568
+ (
569
+ "DAX Expressions",
570
+ [
571
+ "Measure",
572
+ "Calculated Table",
573
+ "Calculated Column",
574
+ "Calculation Item",
575
+ ],
576
+ "Error",
577
+ "Column references should be fully qualified",
578
+ lambda obj, tom: any(
579
+ tom.unqualified_columns(object=obj, dependencies=dependencies)
580
+ ),
581
+ "Using fully qualified column references makes it easier to distinguish between column and measure references, and also helps avoid certain errors. When referencing a column in DAX, first specify the table name, then specify the column name in square brackets.",
582
+ "https://www.elegantbi.com/post/top10bestpractices",
583
+ ),
584
+ (
585
+ "DAX Expressions",
586
+ [
587
+ "Measure",
588
+ "Calculated Table",
589
+ "Calculated Column",
590
+ "Calculation Item",
591
+ ],
592
+ "Error",
593
+ "Measure references should be unqualified",
594
+ lambda obj, tom: any(
595
+ tom.fully_qualified_measures(object=obj, dependencies=dependencies)
596
+ ),
597
+ "Using unqualified measure references makes it easier to distinguish between column and measure references, and also helps avoid certain errors. When referencing a measure using DAX, do not specify the table name. Use only the measure name in square brackets.",
598
+ "https://www.elegantbi.com/post/top10bestpractices",
599
+ ),
600
+ (
601
+ "DAX Expressions",
602
+ "Relationship",
603
+ "Warning",
604
+ "Inactive relationships that are never activated",
605
+ lambda obj, tom: obj.IsActive is False
606
+ and not any(
607
+ re.search(
608
+ r"USERELATIONSHIP\s*\(\s*\'*"
609
+ + re.escape(obj.FromTable.Name)
610
+ + r"'*\["
611
+ + re.escape(obj.FromColumn.Name)
612
+ + r"\]\s*,\s*'*"
613
+ + re.escape(obj.ToTable.Name)
614
+ + r"'*\["
615
+ + re.escape(obj.ToColumn.Name)
616
+ + r"\]",
617
+ m.Expression,
618
+ flags=re.IGNORECASE,
619
+ )
620
+ for m in tom.all_measures()
621
+ ),
622
+ "Inactive relationships are activated using the USERELATIONSHIP function. If an inactive relationship is not referenced in any measure via this function, the relationship will not be used. It should be determined whether the relationship is not necessary or to activate the relationship via this method.",
623
+ "https://dax.guide/userelationship",
624
+ ),
625
+ (
626
+ "Maintenance",
627
+ "Column",
628
+ "Warning",
629
+ "Remove unnecessary columns",
630
+ lambda obj, tom: (obj.IsHidden or obj.Parent.IsHidden)
631
+ and not any(tom.used_in_relationships(object=obj))
632
+ and not any(tom.used_in_hierarchies(column=obj))
633
+ and not any(tom.used_in_sort_by(column=obj))
634
+ and any(tom.depends_on(object=obj, dependencies=dependencies)),
635
+ "Hidden columns that are not referenced by any DAX expressions, relationships, hierarchy levels or Sort By-properties should be removed.",
636
+ ),
637
+ (
638
+ "Maintenance",
639
+ "Measure",
640
+ "Warning",
641
+ "Remove unnecessary measures",
642
+ lambda obj, tom: obj.IsHidden
643
+ and not any(tom.referenced_by(object=obj, dependencies=dependencies)),
644
+ "Hidden measures that are not referenced by any DAX expressions should be removed for maintainability.",
645
+ ),
646
+ (
647
+ "Maintenance",
648
+ "Table",
649
+ "Warning",
650
+ "Ensure tables have relationships",
651
+ lambda obj, tom: any(tom.used_in_relationships(object=obj)) is False
652
+ and obj.CalculationGroup is None,
653
+ "This rule highlights tables which are not connected to any other table in the model with a relationship.",
654
+ ),
655
+ (
656
+ "Maintenance",
657
+ "Table",
658
+ "Warning",
659
+ "Calculation groups with no calculation items",
660
+ lambda obj, tom: obj.CalculationGroup is not None
661
+ and not any(obj.CalculationGroup.CalculationItems),
662
+ "Calculation groups have no function unless they have calculation items.",
663
+ ),
664
+ (
665
+ "Maintenance",
666
+ ["Column", "Measure", "Table"],
667
+ "Info",
668
+ "Visible objects with no description",
669
+ lambda obj, tom: obj.IsHidden is False and len(obj.Description) == 0,
670
+ "Add descriptions to objects. These descriptions are shown on hover within the Field List in Power BI Desktop. Additionally, you can leverage these descriptions to create an automated data dictionary.",
671
+ ),
672
+ (
673
+ "Formatting",
674
+ "Column",
675
+ "Warning",
676
+ "Provide format string for 'Date' columns",
677
+ lambda obj, tom: (re.search(r"date", obj.Name, flags=re.IGNORECASE))
678
+ and (obj.DataType == TOM.DataType.DateTime)
679
+ and (
680
+ obj.FormatString.lower()
681
+ not in [
682
+ "mm/dd/yyyy",
683
+ "mm-dd-yyyy",
684
+ "dd/mm/yyyy",
685
+ "dd-mm-yyyy",
686
+ "yyyy-mm-dd",
687
+ "yyyy/mm/dd",
688
+ ]
689
+ ),
690
+ 'Columns of type "DateTime" that have "Date" in their names should be formatted.',
691
+ ),
692
+ (
693
+ "Formatting",
694
+ "Column",
695
+ "Warning",
696
+ "Do not summarize numeric columns",
697
+ lambda obj, tom: (
698
+ (obj.DataType == TOM.DataType.Int64)
699
+ or (obj.DataType == TOM.DataType.Decimal)
700
+ or (obj.DataType == TOM.DataType.Double)
701
+ )
702
+ and (str(obj.SummarizeBy) != "None")
703
+ and not ((obj.IsHidden) or (obj.Parent.IsHidden)),
704
+ 'Numeric columns (integer, decimal, double) should have their SummarizeBy property set to "None" to avoid accidental summation in Power BI (create measures instead).',
705
+ ),
706
+ (
707
+ "Formatting",
708
+ "Measure",
709
+ "Info",
710
+ "Provide format string for measures",
711
+ lambda obj, tom: obj.IsHidden is False and len(obj.FormatString) == 0,
712
+ "Visible measures should have their format string property assigned.",
713
+ ),
714
+ (
715
+ "Formatting",
716
+ "Column",
717
+ "Info",
718
+ "Add data category for columns",
719
+ lambda obj, tom: len(obj.DataCategory) == 0
720
+ and any(
721
+ obj.Name.lower().startswith(item.lower())
722
+ for item in [
723
+ "country",
724
+ "city",
725
+ "continent",
726
+ "latitude",
727
+ "longitude",
728
+ ]
729
+ ),
730
+ "Add Data Category property for appropriate columns.",
731
+ "https://docs.microsoft.com/power-bi/transform-model/desktop-data-categorization",
732
+ ),
733
+ (
734
+ "Formatting",
735
+ "Measure",
736
+ "Warning",
737
+ "Percentages should be formatted with thousands separators and 1 decimal",
738
+ lambda obj, tom: "%" in obj.FormatString
739
+ and obj.FormatString != "#,0.0%;-#,0.0%;#,0.0%",
740
+ "For a better user experience, percengage measures should be formatted with a '%' sign.",
741
+ ),
742
+ (
743
+ "Formatting",
744
+ "Measure",
745
+ "Warning",
746
+ "Whole numbers should be formatted with thousands separators and no decimals",
747
+ lambda obj, tom: "$" not in obj.FormatString
748
+ and "%" not in obj.FormatString
749
+ and obj.FormatString not in ["#,0", "#,0.0"],
750
+ "For a better user experience, whole numbers should be formatted with commas.",
751
+ ),
752
+ (
753
+ "Formatting",
754
+ "Column",
755
+ "Info",
756
+ "Hide foreign keys",
757
+ lambda obj, tom: obj.IsHidden is False
758
+ and any(
759
+ r.FromColumn.Name == obj.Name
760
+ and r.FromCardinality == TOM.RelationshipEndCardinality.Many
761
+ for r in tom.used_in_relationships(object=obj)
762
+ ),
763
+ "Foreign keys should always be hidden as they should not be used by end users.",
764
+ ),
765
+ (
766
+ "Formatting",
767
+ "Column",
768
+ "Info",
769
+ "Mark primary keys",
770
+ lambda obj, tom: any(
771
+ r.ToTable.Name == obj.Table.Name
772
+ and r.ToColumn.Name == obj.Name
773
+ and r.ToCardinality == TOM.RelationshipEndCardinality.One
774
+ for r in tom.used_in_relationships(object=obj)
775
+ )
776
+ and obj.IsKey is False
777
+ and obj.Table.DataCategory != "Time",
778
+ "Set the 'Key' property to 'True' for primary key columns within the column properties.",
779
+ ),
780
+ (
781
+ "Formatting",
782
+ "Column",
783
+ "Info",
784
+ "Month (as a string) must be sorted",
785
+ lambda obj, tom: (re.search(r"month", obj.Name, flags=re.IGNORECASE))
786
+ and not (re.search(r"months", obj.Name, flags=re.IGNORECASE))
787
+ and (obj.DataType == TOM.DataType.String)
788
+ and len(str(obj.SortByColumn)) == 0,
789
+ "This rule highlights month columns which are strings and are not sorted. If left unsorted, they will sort alphabetically (i.e. April, August...). Make sure to sort such columns so that they sort properly (January, February, March...).",
790
+ ),
791
+ (
792
+ "Formatting",
793
+ "Relationship",
794
+ "Warning",
795
+ "Relationship columns should be of integer data type",
796
+ lambda obj, tom: obj.FromColumn.DataType != TOM.DataType.Int64
797
+ or obj.ToColumn.DataType != TOM.DataType.Int64,
798
+ "It is a best practice for relationship columns to be of integer data type. This applies not only to data warehousing but data modeling as well.",
799
+ ),
800
+ (
801
+ "Formatting",
802
+ "Column",
803
+ "Warning",
804
+ "Provide format string for 'Month' columns",
805
+ lambda obj, tom: re.search(r"month", obj.Name, flags=re.IGNORECASE)
806
+ and obj.DataType == TOM.DataType.DateTime
807
+ and obj.FormatString != "MMMM yyyy",
808
+ 'Columns of type "DateTime" that have "Month" in their names should be formatted as "MMMM yyyy".',
809
+ ),
810
+ (
811
+ "Formatting",
812
+ "Column",
813
+ "Info",
814
+ "Format flag columns as Yes/No value strings",
815
+ lambda obj, tom: obj.Name.lower().startswith("is")
816
+ and obj.DataType == TOM.DataType.Int64
817
+ and not (obj.IsHidden or obj.Parent.IsHidden)
818
+ or obj.Name.lower().endswith(" flag")
819
+ and obj.DataType != TOM.DataType.String
820
+ and not (obj.IsHidden or obj.Parent.IsHidden),
821
+ "Flags must be properly formatted as Yes/No as this is easier to read than using 0/1 integer values.",
822
+ ),
823
+ (
824
+ "Formatting",
825
+ ["Table", "Column", "Measure", "Partition", "Hierarchy"],
826
+ "Error",
827
+ "Objects should not start or end with a space",
828
+ lambda obj, tom: obj.Name[0] == " " or obj.Name[-1] == " ",
829
+ "Objects should not start or end with a space. This usually happens by accident and is difficult to find.",
830
+ ),
831
+ (
832
+ "Formatting",
833
+ ["Table", "Column", "Measure", "Partition", "Hierarchy"],
834
+ "Info",
835
+ "First letter of objects must be capitalized",
836
+ lambda obj, tom: obj.Name[0] != obj.Name[0].upper(),
837
+ "The first letter of object names should be capitalized to maintain professional quality.",
838
+ ),
839
+ (
840
+ "Naming Conventions",
841
+ ["Table", "Column", "Measure", "Partition", "Hierarchy"],
842
+ "Warning",
843
+ "Object names must not contain special characters",
844
+ lambda obj, tom: re.search(r"[\t\r\n]", obj.Name),
845
+ "Object names should not include tabs, line breaks, etc.",
846
+ ),
847
+ ],
848
+ columns=[
849
+ "Category",
850
+ "Scope",
851
+ "Severity",
852
+ "Rule Name",
853
+ "Expression",
854
+ "Description",
855
+ "URL",
856
+ ],
857
+ )
858
+
859
+ return rules