Skip to content

Commit 0fcb3bc

Browse files
committed
Import version 0.1.2
1 parent 2479357 commit 0fcb3bc

7 files changed

Lines changed: 235 additions & 68 deletions

File tree

src/AbcClassification/README.md

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
# DaxPatterns.AbcClassification
2+
3+
Functions to implement the [ABC Classification](https://www.daxpatterns.com/abc-classification/) pattern (dynamic version) from [DAX Patterns](https://www.daxpatterns.com/).
4+
5+
## What it does
6+
7+
`ComputeInAbcClass` evaluates an expression by filtering the *entity* (e.g., Product, Customer) belongs to the ABC classes active in the filter context from a disconnected “ABC Classes” table, **respecting all active report filters**. Use it to build dynamic ABC analyses that slice by time, region, or any other dimension. ([daxpatterns.com][1])
8+
9+
---
10+
11+
## Function
12+
13+
```DAX
14+
ComputeInAbcClass (
15+
<valueExpr>, -- e.g., [Sales Amount] (must be additive, SUM-based)
16+
<transactionsTable>, -- e.g., Sales
17+
<itemTable>, -- e.g., 'Product'
18+
<itemKeyColumn>, -- e.g., 'Product'[ProductKey]
19+
<abcClassTable>, -- e.g., 'ABC Classes' (disconnected)
20+
<abcLowerBoundaryColumn>, -- e.g., 'ABC Classes'[Lower Boundary] -- inclusive
21+
<abcUpperBoundaryColumn] -- e.g., 'ABC Classes'[Upper Boundary] -- exclusive (see notes)
22+
)
23+
```
24+
25+
**Return:** `TRUE` if the entity’s cumulative share (by `<valueExpr>`) falls within the class boundaries on the current row of `<abcClassTable>`. Otherwise `FALSE`. Use it inside measures to filter or label entities.
26+
27+
**Assumptions:** Dynamic ABC as in the DAX Patterns article with a parameter table of class boundaries. The measure supplied must aggregate with `SUM`. ([daxpatterns.com][1])
28+
29+
---
30+
31+
## Model requirements
32+
33+
1. **Value measure:** Additive, e.g.:
34+
35+
```DAX
36+
Sales Amount =
37+
SUMX ( Sales, Sales[Quantity] * Sales[Net Price] )
38+
```
39+
2. **Entity table:** The table that lists the items to classify (e.g., `Product`).
40+
3. **Classes table (disconnected):** No relationships. Contains at least:
41+
42+
* `Class` (A/B/C or any label)
43+
* `Lower Boundary` (0–1)
44+
* `Upper Boundary` (0–1)
45+
46+
Example `ABC Classes` (typical Pareto configuration):
47+
48+
```DAX
49+
ABC Classes =
50+
DATATABLE (
51+
"Class", STRING,
52+
"Lower Boundary", DOUBLE,
53+
"Upper Boundary", DOUBLE,
54+
{
55+
{ "A", 0.00, 0.70 },
56+
{ "B", 0.70, 0.90 },
57+
{ "C", 0.90, 1.00 }
58+
})
59+
```
60+
61+
This matches the pattern described in DAX Patterns and its dynamic variant (classification driven by a disconnected parameter table). ([daxpatterns.com][1])
62+
63+
---
64+
65+
## Basic usage
66+
67+
```DAX
68+
ABC Sales Amount =
69+
ComputeInAbcClass (
70+
[Sales Amount],
71+
Sales,
72+
'Product',
73+
'Product'[ProductKey],
74+
'ABC Classes',
75+
'ABC Classes'[Lower Boundary],
76+
'ABC Classes'[Upper Boundary]
77+
)
78+
79+
```
80+
81+
These produce a **dynamic** ABC where class membership updates with filters (e.g., year, region). ([daxpatterns.com][1])
82+
83+
---
84+
85+
## Tips, constraints, and performance
86+
87+
* **Additivity:** `<valueExpr>` must be SUM-based for correct cumulative ranking in the dynamic pattern. Non-additive measures break the logic. ([daxpatterns.com][1])
88+
* **Boundaries:** Treat `Lower Boundary` as inclusive and `Upper Boundary` as exclusive to avoid overlaps at exact cut points (e.g., 0.70 belongs to B if A ends at 0.70).
89+
* **Disconnected classes:** Do **not** relate `ABC Classes` to other tables. It is a parameter table used by the measure. ([daxpatterns.com][2])
90+
* **Granularity:** Pass the **entity key** that defines classification granularity.
91+
* **Scaling:** With very high entity cardinality, consider pre-aggregation by entity or snapshot ABC when dynamics are not needed. ([daxpatterns.com][1])
92+
93+
---
94+
95+
## Related reading
96+
97+
* DAX Patterns — ABC classification (static, snapshot, dynamic). ([daxpatterns.com][1])
98+
* DAX Patterns — Dynamic ABC Classification (concepts and step-by-step). ([daxpatterns.com][1])
99+
* Parameter Table pattern. ([daxpatterns.com][2])
100+
* DAX Lib package list (package reference). ([daxlib.org][3])
101+
102+
---
103+
104+
## License
105+
106+
MIT License.
107+
108+
[1]: https://www.daxpatterns.com/abc-classification/ "ABC classification"
109+
[2]: https://www.daxpatterns.com/parameter-table/ "Parameter table"
110+
[3]: https://daxlib.org/packages/ "Packages - Extend Power BI with DAX Lib"

src/AbcClassification/icon.png

11.3 KB
Loading
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
/// Return the value computed in the filtered ABC classes
2+
/// Implement Dynamic ABC Classification pattern from DAX Patterns
3+
/// Article: https://www.daxpatterns.com/abc-classification/
4+
/// You must have a table with the definition of
5+
/// the ABC classes (abcClassTable) with at least two columns,
6+
/// the lower and the upper boundary of each class
7+
/// The first argument is the expression to evaluate for each
8+
/// ite in itemTable, which cardinality is expressed by itemKeyColumn
9+
/// The transactionTable is the table that defines the presence of
10+
/// transactions, typically the table that has the column(s)
11+
/// aggregated in valueExpr
12+
function 'DaxPatterns.AbcClassification.ComputeInAbcClass' = ```
13+
(
14+
valueExpr : ANYREF EXPR,
15+
transactionsTable : ANYREF EXPR,
16+
itemTable : ANYREF EXPR,
17+
itemKeyColumn : ANYREF EXPR,
18+
abcClassTable : ANYREF EXPR,
19+
abcLowerBoundaryColumn : ANYREF EXPR,
20+
abcUpperBoundaryColumn : ANYREF EXPR
21+
) =>
22+
VAR ProductsInClass =
23+
DaxPatterns.AbcClassification.ItemsInClass(
24+
valueExpr,
25+
TransactionsTable,
26+
ItemTable,
27+
ItemKeyColumn,
28+
abcClassTable,
29+
abcLowerBoundaryColumn,
30+
abcUpperBoundaryColumn
31+
)
32+
VAR Result =
33+
CALCULATE (
34+
valueExpr,
35+
KEEPFILTERS ( ProductsInClass )
36+
)
37+
RETURN Result
38+
```
39+
annotation DAXLIB_PackageId = DaxPatterns.AbcClassification
40+
41+
annotation DAXLIB_PackageVersion = 0.1.2
42+
43+
/// Return the items filtered by ABC classes
44+
/// Implement Dynamic ABC Classification pattern from DAX Patterns
45+
/// Article: https://www.daxpatterns.com/abc-classification/
46+
/// You must have a table with the definition of
47+
/// the ABC classes (abcClassTable) with at least two columns,
48+
/// the lower and the upper boundary of each class
49+
/// The first argument is the expression to evaluate for each
50+
/// ite in itemTable, which cardinality is expressed by itemKeyColumn
51+
/// The transactionTable is the table that defines the presence of
52+
/// transactions, typically the table that has the column(s)
53+
/// aggregated in valueExpr
54+
function 'DaxPatterns.AbcClassification.ItemsInClass' = ```
55+
(
56+
valueExpr : ANYREF EXPR,
57+
transactionsTable : ANYREF EXPR,
58+
itemTable : ANYREF EXPR,
59+
itemKeyColumn : ANYREF EXPR,
60+
abcClassTable : ANYREF EXPR,
61+
abcLowerBoundaryColumn : ANYREF EXPR,
62+
abcUpperBoundaryColumn : ANYREF EXPR
63+
) =>
64+
VAR TransactionsByItem =
65+
CALCULATETABLE (
66+
ADDCOLUMNS (
67+
SUMMARIZE ( transactionsTable, itemKeyColumn ),
68+
"@Value", CALCULATE ( valueExpr )
69+
),
70+
ALLSELECTED ( itemTable )
71+
)
72+
VAR AllItemsValue =
73+
SUMX (
74+
transactionsByItem,
75+
[@Value]
76+
)
77+
VAR CumulatedPctByItemTable =
78+
ADDCOLUMNS (
79+
transactionsByItem,
80+
"@CumulatedPct",
81+
VAR CumulatedValue =
82+
SUMX (
83+
WINDOW (
84+
1, ABS,
85+
0, REL,
86+
transactionsByItem,
87+
ORDERBY ( [@Value], DESC )
88+
),
89+
[@Value]
90+
)
91+
VAR Perc =
92+
DIVIDE (
93+
CumulatedValue,
94+
AllItemsValue
95+
)
96+
RETURN
97+
MIN ( Perc, 1 ) -- Avoid >100% in case of rounding issues
98+
)
99+
100+
VAR Result =
101+
FILTER (
102+
CROSSJOIN (
103+
CumulatedPctByItemTable,
104+
abcClassTable
105+
),
106+
AND (
107+
[@CumulatedPct] > abcLowerBoundaryColumn,
108+
[@CumulatedPct] <= abcUpperBoundaryColumn
109+
)
110+
)
111+
RETURN Result
112+
```
113+
annotation DAXLIB_PackageId = DaxPatterns.AbcClassification
114+
115+
annotation DAXLIB_PackageVersion = 0.1.2
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"$schema": "https://raw.githubusercontent.com/sql-bi/daxlib/refs/heads/main/schemas/manifest/1.0.0/manifest.1.0.0.schema.json",
3+
"id": "DaxPatterns.AbcClassification",
4+
"version": "0.1.2",
5+
"authors": "SQLBI",
6+
"description": "Implementation of ABC Classification patterns using User Defined Functions.",
7+
"tags": "DAX,UDF,FUNCTION,LIB,PATTERN,ABC",
8+
"icon": "/icon.png",
9+
"readme": "/README.md"
10+
}

src/README.md

Lines changed: 0 additions & 25 deletions
This file was deleted.

src/lib/functions.tmdl

Lines changed: 0 additions & 32 deletions
This file was deleted.

src/manifest.daxlib

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)