Forum Discussion
Calculated most used text in new column
- 1 year ago
DAX for Calculated Column
Outcome =
VAR CurrentCustomer = Table1[Customer ID]
VAR ProductCounts =
ADDCOLUMNS (
SUMMARIZE ( Table1, Table1[Customer ID], Table1[Product] ),
"ProdCount",
CALCULATE (
COUNTROWS ( Table1 ),
ALLEXCEPT ( Table1, Table1[Customer ID], Table1[Product] )
)
)
VAR TopProduct =
TOPN (
1,
FILTER ( ProductCounts, [Customer ID] = CurrentCustomer ),
[ProdCount],
DESC
)
RETURN
MAXX ( TopProduct, Table1[Product] ) - 1 year ago
You can create a calculated column like
Test = VAR ProductsAndCount = CALCULATETABLE( SUMMARIZECOLUMNS( 'Table'[Product], "@num", COUNTROWS( 'Table' ) ), ALLEXCEPT( 'Table', 'Table'[Customer ID] ) ) VAR Result = SELECTCOLUMNS( INDEX( 1, ProductsAndCount, ORDERBY( [@num], DESC ) ), "@prod", 'Table'[Product] ) RETURN Result
DAX for Calculated Column
Outcome =
VAR CurrentCustomer = Table1[Customer ID]
VAR ProductCounts =
ADDCOLUMNS (
SUMMARIZE ( Table1, Table1[Customer ID], Table1[Product] ),
"ProdCount",
CALCULATE (
COUNTROWS ( Table1 ),
ALLEXCEPT ( Table1, Table1[Customer ID], Table1[Product] )
)
)
VAR TopProduct =
TOPN (
1,
FILTER ( ProductCounts, [Customer ID] = CurrentCustomer ),
[ProdCount],
DESC
)
RETURN
MAXX ( TopProduct, Table1[Product] )