@luquimbo/bi-superpowers 1.0.0

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 (193) hide show
  1. package/.claude-plugin/plugin.json +8 -0
  2. package/.mcp.json +25 -0
  3. package/AGENTS.md +244 -0
  4. package/CHANGELOG.md +265 -0
  5. package/LICENSE +21 -0
  6. package/README.md +211 -0
  7. package/bin/build-plugin.js +30 -0
  8. package/bin/cli.js +1064 -0
  9. package/bin/commands/add.js +533 -0
  10. package/bin/commands/add.test.js +77 -0
  11. package/bin/commands/build-desktop.js +166 -0
  12. package/bin/commands/changelog.js +443 -0
  13. package/bin/commands/diff.js +325 -0
  14. package/bin/commands/lint.js +419 -0
  15. package/bin/commands/lint.test.js +103 -0
  16. package/bin/commands/mcp-setup.js +246 -0
  17. package/bin/commands/pull.js +287 -0
  18. package/bin/commands/pull.test.js +36 -0
  19. package/bin/commands/push.js +231 -0
  20. package/bin/commands/push.test.js +14 -0
  21. package/bin/commands/search.js +344 -0
  22. package/bin/commands/search.test.js +115 -0
  23. package/bin/commands/setup.js +545 -0
  24. package/bin/commands/setup.test.js +46 -0
  25. package/bin/commands/sync-profile.js +405 -0
  26. package/bin/commands/sync-profile.test.js +14 -0
  27. package/bin/commands/sync-source.js +418 -0
  28. package/bin/commands/sync-source.test.js +14 -0
  29. package/bin/commands/watch.js +206 -0
  30. package/bin/lib/generators/claude-plugin.js +266 -0
  31. package/bin/lib/generators/claude-plugin.test.js +110 -0
  32. package/bin/lib/generators/index.js +116 -0
  33. package/bin/lib/generators/shared.js +282 -0
  34. package/bin/lib/licensing/index.js +35 -0
  35. package/bin/lib/licensing/storage.js +364 -0
  36. package/bin/lib/licensing/storage.test.js +55 -0
  37. package/bin/lib/licensing/validator.js +213 -0
  38. package/bin/lib/licensing/validator.test.js +137 -0
  39. package/bin/lib/microsoft-mcp.js +176 -0
  40. package/bin/lib/microsoft-mcp.test.js +106 -0
  41. package/bin/lib/skills.js +84 -0
  42. package/bin/mcp/powerbi-modeling-launcher.js +38 -0
  43. package/bin/postinstall.js +44 -0
  44. package/bin/utils/errors.js +159 -0
  45. package/bin/utils/git.js +298 -0
  46. package/bin/utils/logger.js +142 -0
  47. package/bin/utils/mcp-detect.js +274 -0
  48. package/bin/utils/mcp-detect.test.js +105 -0
  49. package/bin/utils/pbix.js +305 -0
  50. package/bin/utils/pbix.test.js +37 -0
  51. package/bin/utils/profiles.js +312 -0
  52. package/bin/utils/projects.js +168 -0
  53. package/bin/utils/readline.js +206 -0
  54. package/bin/utils/readline.test.js +47 -0
  55. package/bin/utils/tui.js +314 -0
  56. package/bin/utils/tui.test.js +127 -0
  57. package/commands/contributions.md +265 -0
  58. package/commands/data-model-design.md +468 -0
  59. package/commands/dax-doctor.md +248 -0
  60. package/commands/fabric-scripts.md +452 -0
  61. package/commands/migration-assistant.md +290 -0
  62. package/commands/model-documenter.md +242 -0
  63. package/commands/pbi-connect.md +239 -0
  64. package/commands/project-kickoff.md +905 -0
  65. package/commands/report-layout.md +296 -0
  66. package/commands/rls-design.md +533 -0
  67. package/commands/theme-tweaker.md +624 -0
  68. package/config.example.json +23 -0
  69. package/config.json +23 -0
  70. package/desktop-extension/manifest.json +37 -0
  71. package/desktop-extension/package.json +10 -0
  72. package/desktop-extension/server.js +95 -0
  73. package/docs/openrouter-free-models.md +92 -0
  74. package/library/examples/README.md +151 -0
  75. package/library/examples/finance-reporting/README.md +351 -0
  76. package/library/examples/finance-reporting/data-model.md +267 -0
  77. package/library/examples/finance-reporting/measures.dax +557 -0
  78. package/library/examples/hr-analytics/README.md +371 -0
  79. package/library/examples/hr-analytics/data-model.md +315 -0
  80. package/library/examples/hr-analytics/measures.dax +460 -0
  81. package/library/examples/marketing-analytics/README.md +37 -0
  82. package/library/examples/marketing-analytics/data-model.md +62 -0
  83. package/library/examples/marketing-analytics/measures.dax +110 -0
  84. package/library/examples/retail-analytics/README.md +439 -0
  85. package/library/examples/retail-analytics/data-model.md +288 -0
  86. package/library/examples/retail-analytics/measures.dax +481 -0
  87. package/library/examples/supply-chain/README.md +37 -0
  88. package/library/examples/supply-chain/data-model.md +69 -0
  89. package/library/examples/supply-chain/measures.dax +77 -0
  90. package/library/examples/udf-library/README.md +228 -0
  91. package/library/examples/udf-library/functions.dax +571 -0
  92. package/library/snippets/dax/README.md +292 -0
  93. package/library/snippets/dax/business-domains.md +576 -0
  94. package/library/snippets/dax/calculate-patterns.md +276 -0
  95. package/library/snippets/dax/calculation-groups.md +489 -0
  96. package/library/snippets/dax/error-handling.md +495 -0
  97. package/library/snippets/dax/iterators-and-aggregations.md +474 -0
  98. package/library/snippets/dax/kpis-and-metrics.md +293 -0
  99. package/library/snippets/dax/rankings-and-topn.md +235 -0
  100. package/library/snippets/dax/security-patterns.md +413 -0
  101. package/library/snippets/dax/text-and-formatting.md +316 -0
  102. package/library/snippets/dax/time-intelligence.md +196 -0
  103. package/library/snippets/dax/user-defined-functions.md +477 -0
  104. package/library/snippets/dax/virtual-tables.md +546 -0
  105. package/library/snippets/excel-formulas/README.md +84 -0
  106. package/library/snippets/excel-formulas/aggregations.md +330 -0
  107. package/library/snippets/excel-formulas/dates-and-times.md +361 -0
  108. package/library/snippets/excel-formulas/dynamic-arrays.md +314 -0
  109. package/library/snippets/excel-formulas/lookups.md +169 -0
  110. package/library/snippets/excel-formulas/text-functions.md +363 -0
  111. package/library/snippets/governance/naming-conventions.md +97 -0
  112. package/library/snippets/governance/review-checklists.md +107 -0
  113. package/library/snippets/power-query/README.md +389 -0
  114. package/library/snippets/power-query/api-integration.md +707 -0
  115. package/library/snippets/power-query/connections.md +434 -0
  116. package/library/snippets/power-query/data-cleaning.md +298 -0
  117. package/library/snippets/power-query/error-handling.md +526 -0
  118. package/library/snippets/power-query/parameters.md +350 -0
  119. package/library/snippets/power-query/performance.md +506 -0
  120. package/library/snippets/power-query/transformations.md +330 -0
  121. package/library/snippets/report-design/accessibility.md +78 -0
  122. package/library/snippets/report-design/chart-selection.md +54 -0
  123. package/library/snippets/report-design/layout-patterns.md +87 -0
  124. package/library/templates/data-models/README.md +93 -0
  125. package/library/templates/data-models/finance-model.md +627 -0
  126. package/library/templates/data-models/retail-star-schema.md +473 -0
  127. package/library/templates/excel/README.md +83 -0
  128. package/library/templates/excel/budget-tracker.md +432 -0
  129. package/library/templates/excel/data-entry-form.md +533 -0
  130. package/library/templates/power-bi/README.md +72 -0
  131. package/library/templates/power-bi/finance-report.md +449 -0
  132. package/library/templates/power-bi/kpi-scorecard.md +461 -0
  133. package/library/templates/power-bi/sales-dashboard.md +281 -0
  134. package/library/themes/excel/README.md +436 -0
  135. package/library/themes/power-bi/README.md +271 -0
  136. package/library/themes/power-bi/accessible.json +307 -0
  137. package/library/themes/power-bi/bi-superpowers-default.json +858 -0
  138. package/library/themes/power-bi/corporate-blue.json +291 -0
  139. package/library/themes/power-bi/dark-mode.json +291 -0
  140. package/library/themes/power-bi/minimal.json +292 -0
  141. package/library/themes/power-bi/print-friendly.json +309 -0
  142. package/package.json +93 -0
  143. package/skills/contributions/SKILL.md +267 -0
  144. package/skills/data-model-design/SKILL.md +470 -0
  145. package/skills/data-modeling/SKILL.md +254 -0
  146. package/skills/data-quality/SKILL.md +664 -0
  147. package/skills/dax/SKILL.md +708 -0
  148. package/skills/dax-doctor/SKILL.md +250 -0
  149. package/skills/dax-udf/SKILL.md +489 -0
  150. package/skills/deployment/SKILL.md +320 -0
  151. package/skills/excel-formulas/SKILL.md +463 -0
  152. package/skills/fabric-scripts/SKILL.md +454 -0
  153. package/skills/fast-standard/SKILL.md +509 -0
  154. package/skills/governance/SKILL.md +205 -0
  155. package/skills/migration-assistant/SKILL.md +292 -0
  156. package/skills/model-documenter/SKILL.md +244 -0
  157. package/skills/pbi-connect/SKILL.md +241 -0
  158. package/skills/power-query/SKILL.md +406 -0
  159. package/skills/project-kickoff/SKILL.md +907 -0
  160. package/skills/query-performance/SKILL.md +480 -0
  161. package/skills/report-design/SKILL.md +207 -0
  162. package/skills/report-layout/SKILL.md +298 -0
  163. package/skills/rls-design/SKILL.md +535 -0
  164. package/skills/semantic-model/SKILL.md +237 -0
  165. package/skills/testing-validation/SKILL.md +643 -0
  166. package/skills/theme-tweaker/SKILL.md +626 -0
  167. package/src/content/base.md +237 -0
  168. package/src/content/mcp-requirements.json +69 -0
  169. package/src/content/routing.md +203 -0
  170. package/src/content/skills/contributions.md +259 -0
  171. package/src/content/skills/data-model-design.md +462 -0
  172. package/src/content/skills/data-modeling.md +246 -0
  173. package/src/content/skills/data-quality.md +656 -0
  174. package/src/content/skills/dax-doctor.md +242 -0
  175. package/src/content/skills/dax-udf.md +481 -0
  176. package/src/content/skills/dax.md +700 -0
  177. package/src/content/skills/deployment.md +312 -0
  178. package/src/content/skills/excel-formulas.md +455 -0
  179. package/src/content/skills/fabric-scripts.md +446 -0
  180. package/src/content/skills/fast-standard.md +501 -0
  181. package/src/content/skills/governance.md +197 -0
  182. package/src/content/skills/migration-assistant.md +284 -0
  183. package/src/content/skills/model-documenter.md +236 -0
  184. package/src/content/skills/pbi-connect.md +233 -0
  185. package/src/content/skills/power-query.md +398 -0
  186. package/src/content/skills/project-kickoff.md +899 -0
  187. package/src/content/skills/query-performance.md +472 -0
  188. package/src/content/skills/report-design.md +199 -0
  189. package/src/content/skills/report-layout.md +290 -0
  190. package/src/content/skills/rls-design.md +527 -0
  191. package/src/content/skills/semantic-model.md +229 -0
  192. package/src/content/skills/testing-validation.md +635 -0
  193. package/src/content/skills/theme-tweaker.md +618 -0
@@ -0,0 +1,576 @@
1
+ # Business Domain DAX Patterns
2
+
3
+ Ready-to-use DAX measures for common business scenarios across industries.
4
+
5
+ ---
6
+
7
+ ## Retail & E-Commerce
8
+
9
+ ### Sales Performance
10
+
11
+ ```dax
12
+ // Total Revenue
13
+ Total Revenue = SUM(Sales[Amount])
14
+
15
+ // Average Order Value
16
+ Average Order Value = DIVIDE([Total Revenue], DISTINCTCOUNT(Sales[OrderID]))
17
+
18
+ // Average Items per Order
19
+ Items per Order = DIVIDE(SUM(Sales[Quantity]), DISTINCTCOUNT(Sales[OrderID]))
20
+
21
+ // Revenue per Customer
22
+ Revenue per Customer = DIVIDE([Total Revenue], DISTINCTCOUNT(Sales[CustomerID]))
23
+
24
+ // Basket Size (monetary)
25
+ Basket Size = DIVIDE([Total Revenue], COUNTROWS(Sales))
26
+ ```
27
+
28
+ ### Product Analysis
29
+
30
+ ```dax
31
+ // Gross Margin
32
+ Gross Margin = [Total Revenue] - SUM(Sales[Cost])
33
+
34
+ // Gross Margin %
35
+ Gross Margin % = DIVIDE([Gross Margin], [Total Revenue])
36
+
37
+ // Product Contribution %
38
+ Product Contribution % = DIVIDE(
39
+ [Total Revenue],
40
+ CALCULATE([Total Revenue], ALL(Products))
41
+ )
42
+
43
+ // Sell-Through Rate (for inventory)
44
+ Sell Through Rate = DIVIDE(
45
+ SUM(Sales[Quantity]),
46
+ SUM(Inventory[StartingQuantity])
47
+ )
48
+ ```
49
+
50
+ ### Customer Metrics
51
+
52
+ ```dax
53
+ // Customer Count
54
+ Customer Count = DISTINCTCOUNT(Sales[CustomerID])
55
+
56
+ // New Customers (first purchase this period)
57
+ New Customers =
58
+ VAR _CurrentDates = VALUES('Date'[Date])
59
+ RETURN
60
+ CALCULATE(
61
+ DISTINCTCOUNT(Sales[CustomerID]),
62
+ FILTER(
63
+ ALL(Sales),
64
+ Sales[CustomerID] IN CALCULATETABLE(
65
+ VALUES(Sales[CustomerID]),
66
+ _CurrentDates
67
+ ) &&
68
+ CALCULATE(MIN(Sales[OrderDate]), ALL('Date')) IN _CurrentDates
69
+ )
70
+ )
71
+
72
+ // Repeat Customer Rate
73
+ Repeat Customer Rate =
74
+ VAR _CustomersWithMultipleOrders =
75
+ CALCULATE(
76
+ DISTINCTCOUNT(Sales[CustomerID]),
77
+ FILTER(
78
+ SUMMARIZE(Sales, Sales[CustomerID], "Orders", DISTINCTCOUNT(Sales[OrderID])),
79
+ [Orders] > 1
80
+ )
81
+ )
82
+ RETURN
83
+ DIVIDE(_CustomersWithMultipleOrders, [Customer Count])
84
+
85
+ // Customer Lifetime Value (simplified)
86
+ Customer LTV = DIVIDE([Total Revenue], [Customer Count])
87
+ ```
88
+
89
+ ---
90
+
91
+ ## Financial Services
92
+
93
+ ### Revenue & Profitability
94
+
95
+ ```dax
96
+ // Net Interest Income
97
+ Net Interest Income = [Interest Income] - [Interest Expense]
98
+
99
+ // Net Interest Margin (NIM)
100
+ Net Interest Margin = DIVIDE(
101
+ [Net Interest Income],
102
+ AVERAGE(Assets[AverageAssets])
103
+ ) * 100
104
+
105
+ // Return on Assets (ROA)
106
+ ROA = DIVIDE([Net Income], AVERAGE(Assets[TotalAssets])) * 100
107
+
108
+ // Return on Equity (ROE)
109
+ ROE = DIVIDE([Net Income], AVERAGE(Equity[TotalEquity])) * 100
110
+
111
+ // Cost-to-Income Ratio
112
+ Cost Income Ratio = DIVIDE([Operating Expenses], [Operating Income]) * 100
113
+ ```
114
+
115
+ ### Loan Portfolio
116
+
117
+ ```dax
118
+ // Total Loans Outstanding
119
+ Total Loans = SUM(Loans[Principal])
120
+
121
+ // Non-Performing Loans (NPL)
122
+ NPL Amount = CALCULATE([Total Loans], Loans[Status] = "Non-Performing")
123
+
124
+ // NPL Ratio
125
+ NPL Ratio = DIVIDE([NPL Amount], [Total Loans]) * 100
126
+
127
+ // Loan-to-Deposit Ratio
128
+ LTD Ratio = DIVIDE([Total Loans], [Total Deposits]) * 100
129
+
130
+ // Provision Coverage Ratio
131
+ Provision Coverage = DIVIDE([Loan Provisions], [NPL Amount]) * 100
132
+ ```
133
+
134
+ ---
135
+
136
+ ## Manufacturing & Supply Chain
137
+
138
+ ### Production Metrics
139
+
140
+ ```dax
141
+ // Units Produced
142
+ Units Produced = SUM(Production[Quantity])
143
+
144
+ // Yield Rate
145
+ Yield Rate = DIVIDE(
146
+ SUM(Production[GoodUnits]),
147
+ SUM(Production[TotalUnits])
148
+ ) * 100
149
+
150
+ // Defect Rate
151
+ Defect Rate = DIVIDE(
152
+ SUM(Production[DefectiveUnits]),
153
+ SUM(Production[TotalUnits])
154
+ ) * 100
155
+
156
+ // Overall Equipment Effectiveness (OEE)
157
+ OEE =
158
+ VAR _Availability = DIVIDE([Actual Runtime], [Planned Runtime])
159
+ VAR _Performance = DIVIDE([Actual Output], [Theoretical Output])
160
+ VAR _Quality = DIVIDE([Good Units], [Total Units])
161
+ RETURN
162
+ _Availability * _Performance * _Quality * 100
163
+
164
+ // Cycle Time
165
+ Avg Cycle Time = AVERAGE(Production[CycleTimeMinutes])
166
+ ```
167
+
168
+ ### Inventory Management
169
+
170
+ ```dax
171
+ // Total Inventory Value
172
+ Inventory Value = SUMX(Inventory, Inventory[Quantity] * Inventory[UnitCost])
173
+
174
+ // Days of Inventory
175
+ Days of Inventory = DIVIDE(
176
+ [Inventory Value],
177
+ DIVIDE([Cost of Goods Sold], 365)
178
+ )
179
+
180
+ // Inventory Turnover
181
+ Inventory Turnover = DIVIDE([Cost of Goods Sold], [Average Inventory])
182
+
183
+ // Stock-out Rate
184
+ Stockout Rate = DIVIDE(
185
+ CALCULATE(COUNTROWS(Inventory), Inventory[Quantity] = 0),
186
+ COUNTROWS(Inventory)
187
+ ) * 100
188
+
189
+ // Inventory Accuracy
190
+ Inventory Accuracy = DIVIDE(
191
+ SUM(Inventory[SystemCount]),
192
+ SUM(Inventory[PhysicalCount])
193
+ ) * 100
194
+ ```
195
+
196
+ ### Supply Chain Performance
197
+
198
+ ```dax
199
+ // On-Time Delivery Rate
200
+ On Time Delivery = DIVIDE(
201
+ CALCULATE(COUNTROWS(Shipments), Shipments[DeliveryDate] <= Shipments[PromisedDate]),
202
+ COUNTROWS(Shipments)
203
+ ) * 100
204
+
205
+ // Perfect Order Rate
206
+ Perfect Order Rate = DIVIDE(
207
+ CALCULATE(
208
+ COUNTROWS(Orders),
209
+ Orders[OnTime] = TRUE() &&
210
+ Orders[InFull] = TRUE() &&
211
+ Orders[NoDamage] = TRUE() &&
212
+ Orders[AccurateDoc] = TRUE()
213
+ ),
214
+ COUNTROWS(Orders)
215
+ ) * 100
216
+
217
+ // Supplier Lead Time
218
+ Avg Lead Time = AVERAGE(PurchaseOrders[LeadTimeDays])
219
+
220
+ // Order Fill Rate
221
+ Fill Rate = DIVIDE(
222
+ SUM(Orders[QuantityShipped]),
223
+ SUM(Orders[QuantityOrdered])
224
+ ) * 100
225
+ ```
226
+
227
+ ---
228
+
229
+ ## Human Resources
230
+
231
+ ### Headcount & Composition
232
+
233
+ ```dax
234
+ // Total Headcount
235
+ Headcount = COUNTROWS(Employees)
236
+
237
+ // Active Employees
238
+ Active Employees = CALCULATE([Headcount], Employees[Status] = "Active")
239
+
240
+ // FTE (Full-Time Equivalent)
241
+ FTE = SUMX(Employees, Employees[WorkHoursPerWeek] / 40)
242
+
243
+ // Headcount by Department (for visuals)
244
+ Dept Headcount = CALCULATE(
245
+ [Active Employees],
246
+ ALLEXCEPT(Employees, Employees[Department])
247
+ )
248
+
249
+ // Average Tenure (years)
250
+ Avg Tenure = AVERAGEX(
251
+ FILTER(Employees, Employees[Status] = "Active"),
252
+ DATEDIFF(Employees[HireDate], TODAY(), YEAR)
253
+ )
254
+ ```
255
+
256
+ ### Turnover & Retention
257
+
258
+ ```dax
259
+ // Terminations
260
+ Terminations = CALCULATE(
261
+ [Headcount],
262
+ Employees[TerminationDate] <> BLANK(),
263
+ 'Date'[Date] >= MIN(Employees[TerminationDate]),
264
+ 'Date'[Date] <= MAX(Employees[TerminationDate])
265
+ )
266
+
267
+ // Turnover Rate (annual)
268
+ Turnover Rate =
269
+ VAR _TerminationsThisYear = [Terminations]
270
+ VAR _AvgHeadcount = DIVIDE([Active Employees] + [Headcount Last Year], 2)
271
+ RETURN
272
+ DIVIDE(_TerminationsThisYear, _AvgHeadcount) * 100
273
+
274
+ // Voluntary Turnover
275
+ Voluntary Turnover Rate =
276
+ DIVIDE(
277
+ CALCULATE([Terminations], Employees[TerminationType] = "Voluntary"),
278
+ [Average Headcount]
279
+ ) * 100
280
+
281
+ // Retention Rate
282
+ Retention Rate = 100 - [Turnover Rate]
283
+
284
+ // New Hire Retention (90-day)
285
+ New Hire 90 Day Retention =
286
+ VAR _NewHires = CALCULATE([Headcount], Employees[HireDate] >= TODAY() - 90)
287
+ VAR _Retained = CALCULATE(_NewHires, Employees[Status] = "Active")
288
+ RETURN
289
+ DIVIDE(_Retained, _NewHires) * 100
290
+ ```
291
+
292
+ ### Compensation
293
+
294
+ ```dax
295
+ // Total Payroll Cost
296
+ Total Payroll = SUM(Payroll[GrossAmount])
297
+
298
+ // Average Salary
299
+ Avg Salary = AVERAGE(Employees[AnnualSalary])
300
+
301
+ // Revenue per Employee
302
+ Revenue per Employee = DIVIDE([Total Revenue], [Active Employees])
303
+
304
+ // Payroll as % of Revenue
305
+ Payroll to Revenue = DIVIDE([Total Payroll], [Total Revenue]) * 100
306
+
307
+ // Compa-Ratio (salary vs market)
308
+ Compa Ratio = DIVIDE(
309
+ AVERAGE(Employees[AnnualSalary]),
310
+ AVERAGE(Employees[MarketRateMidpoint])
311
+ ) * 100
312
+ ```
313
+
314
+ ---
315
+
316
+ ## Healthcare
317
+
318
+ ### Patient Metrics
319
+
320
+ ```dax
321
+ // Total Patients
322
+ Total Patients = DISTINCTCOUNT(Visits[PatientID])
323
+
324
+ // New Patients
325
+ New Patients =
326
+ CALCULATE(
327
+ DISTINCTCOUNT(Visits[PatientID]),
328
+ FILTER(
329
+ VALUES(Visits[PatientID]),
330
+ CALCULATE(MIN(Visits[VisitDate])) IN VALUES('Date'[Date])
331
+ )
332
+ )
333
+
334
+ // Patient Visits
335
+ Total Visits = COUNTROWS(Visits)
336
+
337
+ // Visits per Patient
338
+ Visits per Patient = DIVIDE([Total Visits], [Total Patients])
339
+
340
+ // Readmission Rate (30-day)
341
+ Readmission Rate 30d =
342
+ VAR _Discharges = COUNTROWS(Admissions)
343
+ VAR _Readmissions = CALCULATE(
344
+ COUNTROWS(Admissions),
345
+ FILTER(
346
+ Admissions,
347
+ CALCULATE(
348
+ COUNTROWS(Admissions),
349
+ FILTER(
350
+ ALL(Admissions),
351
+ Admissions[PatientID] = EARLIER(Admissions[PatientID]) &&
352
+ Admissions[AdmitDate] > EARLIER(Admissions[DischargeDate]) &&
353
+ Admissions[AdmitDate] <= EARLIER(Admissions[DischargeDate]) + 30
354
+ )
355
+ ) > 0
356
+ )
357
+ )
358
+ RETURN
359
+ DIVIDE(_Readmissions, _Discharges) * 100
360
+ ```
361
+
362
+ ### Operational Metrics
363
+
364
+ ```dax
365
+ // Average Length of Stay
366
+ ALOS = AVERAGE(Admissions[LengthOfStay])
367
+
368
+ // Bed Occupancy Rate
369
+ Bed Occupancy = DIVIDE(
370
+ SUM(Census[OccupiedBeds]),
371
+ SUM(Census[AvailableBeds])
372
+ ) * 100
373
+
374
+ // ER Wait Time (average)
375
+ Avg ER Wait = AVERAGE(ERVisits[WaitTimeMinutes])
376
+
377
+ // Surgery Utilization
378
+ OR Utilization = DIVIDE(
379
+ SUM(Surgeries[ActualMinutes]),
380
+ SUM(Surgeries[AvailableMinutes])
381
+ ) * 100
382
+ ```
383
+
384
+ ---
385
+
386
+ ## SaaS & Subscription Business
387
+
388
+ ### Revenue Metrics
389
+
390
+ ```dax
391
+ // Monthly Recurring Revenue (MRR)
392
+ MRR = SUMX(
393
+ FILTER(Subscriptions, Subscriptions[Status] = "Active"),
394
+ Subscriptions[MonthlyAmount]
395
+ )
396
+
397
+ // Annual Recurring Revenue (ARR)
398
+ ARR = [MRR] * 12
399
+
400
+ // Average Revenue per User (ARPU)
401
+ ARPU = DIVIDE([MRR], [Active Subscribers])
402
+
403
+ // Average Revenue per Account (ARPA)
404
+ ARPA = DIVIDE([MRR], DISTINCTCOUNT(Subscriptions[AccountID]))
405
+
406
+ // Expansion MRR
407
+ Expansion MRR = CALCULATE(
408
+ [MRR],
409
+ FILTER(
410
+ Subscriptions,
411
+ Subscriptions[Type] = "Upgrade" || Subscriptions[Type] = "Expansion"
412
+ )
413
+ )
414
+
415
+ // Contraction MRR
416
+ Contraction MRR = CALCULATE(
417
+ [MRR],
418
+ FILTER(
419
+ Subscriptions,
420
+ Subscriptions[Type] = "Downgrade"
421
+ )
422
+ )
423
+
424
+ // Net New MRR
425
+ Net New MRR = [New MRR] + [Expansion MRR] - [Contraction MRR] - [Churned MRR]
426
+ ```
427
+
428
+ ### Customer Metrics
429
+
430
+ ```dax
431
+ // Active Subscribers
432
+ Active Subscribers = CALCULATE(
433
+ DISTINCTCOUNT(Subscriptions[CustomerID]),
434
+ Subscriptions[Status] = "Active"
435
+ )
436
+
437
+ // Churn Rate (monthly)
438
+ Churn Rate =
439
+ VAR _ChurnedCustomers = CALCULATE(
440
+ DISTINCTCOUNT(Subscriptions[CustomerID]),
441
+ Subscriptions[CancelDate] IN VALUES('Date'[Date])
442
+ )
443
+ VAR _StartingCustomers = [Active Subscribers at Period Start]
444
+ RETURN
445
+ DIVIDE(_ChurnedCustomers, _StartingCustomers) * 100
446
+
447
+ // Net Revenue Retention (NRR)
448
+ Net Revenue Retention =
449
+ VAR _StartingMRR = [MRR Last Period from Same Customers]
450
+ VAR _EndingMRR = [MRR This Period from Same Customers]
451
+ RETURN
452
+ DIVIDE(_EndingMRR, _StartingMRR) * 100
453
+
454
+ // Customer Lifetime Value (CLV)
455
+ CLV =
456
+ VAR _AvgMRR = [ARPU]
457
+ VAR _ChurnRate = [Churn Rate] / 100
458
+ VAR _AvgLifetimeMonths = IF(_ChurnRate > 0, DIVIDE(1, _ChurnRate), 60)
459
+ RETURN
460
+ _AvgMRR * _AvgLifetimeMonths
461
+
462
+ // CAC Payback (months)
463
+ CAC Payback Months = DIVIDE([Customer Acquisition Cost], [ARPU])
464
+
465
+ // LTV to CAC Ratio
466
+ LTV CAC Ratio = DIVIDE([CLV], [Customer Acquisition Cost])
467
+ ```
468
+
469
+ ### Engagement Metrics
470
+
471
+ ```dax
472
+ // Daily Active Users (DAU)
473
+ DAU = CALCULATE(
474
+ DISTINCTCOUNT(Usage[UserID]),
475
+ Usage[ActivityDate] = TODAY()
476
+ )
477
+
478
+ // Monthly Active Users (MAU)
479
+ MAU = CALCULATE(
480
+ DISTINCTCOUNT(Usage[UserID]),
481
+ DATESINPERIOD('Date'[Date], TODAY(), -30, DAY)
482
+ )
483
+
484
+ // DAU/MAU Ratio (stickiness)
485
+ Stickiness = DIVIDE([DAU], [MAU]) * 100
486
+
487
+ // Feature Adoption Rate
488
+ Feature Adoption = DIVIDE(
489
+ CALCULATE(DISTINCTCOUNT(Usage[UserID]), Usage[FeatureName] = "NewFeature"),
490
+ [Active Users]
491
+ ) * 100
492
+ ```
493
+
494
+ ---
495
+
496
+ ## Marketing & Sales
497
+
498
+ ### Lead & Pipeline
499
+
500
+ ```dax
501
+ // Total Leads
502
+ Total Leads = COUNTROWS(Leads)
503
+
504
+ // Lead Conversion Rate
505
+ Lead Conversion Rate = DIVIDE(
506
+ CALCULATE([Total Leads], Leads[Status] = "Converted"),
507
+ [Total Leads]
508
+ ) * 100
509
+
510
+ // Pipeline Value
511
+ Pipeline Value = SUM(Opportunities[Amount])
512
+
513
+ // Weighted Pipeline
514
+ Weighted Pipeline = SUMX(
515
+ Opportunities,
516
+ Opportunities[Amount] * Opportunities[Probability]
517
+ )
518
+
519
+ // Win Rate
520
+ Win Rate = DIVIDE(
521
+ CALCULATE(COUNTROWS(Opportunities), Opportunities[Stage] = "Won"),
522
+ CALCULATE(COUNTROWS(Opportunities), Opportunities[IsClosed] = TRUE())
523
+ ) * 100
524
+
525
+ // Average Deal Size
526
+ Avg Deal Size = AVERAGE(FILTER(Opportunities, Opportunities[Stage] = "Won"), Opportunities[Amount])
527
+
528
+ // Sales Cycle Length
529
+ Avg Sales Cycle Days = AVERAGEX(
530
+ FILTER(Opportunities, Opportunities[Stage] = "Won"),
531
+ DATEDIFF(Opportunities[CreatedDate], Opportunities[CloseDate], DAY)
532
+ )
533
+ ```
534
+
535
+ ### Marketing Performance
536
+
537
+ ```dax
538
+ // Customer Acquisition Cost (CAC)
539
+ CAC = DIVIDE([Total Marketing Spend], [New Customers])
540
+
541
+ // Cost per Lead (CPL)
542
+ CPL = DIVIDE([Total Marketing Spend], [Total Leads])
543
+
544
+ // Marketing ROI
545
+ Marketing ROI = DIVIDE(
546
+ [Revenue from New Customers] - [Total Marketing Spend],
547
+ [Total Marketing Spend]
548
+ ) * 100
549
+
550
+ // Campaign Conversion Rate
551
+ Campaign Conversion = DIVIDE(
552
+ CALCULATE(COUNTROWS(Responses), Responses[Converted] = TRUE()),
553
+ COUNTROWS(Responses)
554
+ ) * 100
555
+
556
+ // Email Open Rate
557
+ Email Open Rate = DIVIDE(
558
+ CALCULATE(COUNTROWS(EmailTracking), EmailTracking[Opened] = TRUE()),
559
+ COUNTROWS(EmailTracking)
560
+ ) * 100
561
+
562
+ // Click-Through Rate (CTR)
563
+ CTR = DIVIDE(
564
+ CALCULATE(COUNTROWS(Ads), Ads[Clicks] > 0),
565
+ SUM(Ads[Impressions])
566
+ ) * 100
567
+ ```
568
+
569
+ ---
570
+
571
+ ## Related Resources
572
+
573
+ - [Time Intelligence Patterns](./time-intelligence.md)
574
+ - [KPIs and Metrics](./kpis-and-metrics.md)
575
+ - [Calculate Patterns](./calculate-patterns.md)
576
+ - [DAX Skill](../../skills/dax/SKILL.md)