Forum Discussion
smpa01
Community Champion
4 years agoDAX Table expression to return TOPN by partition
AlexisOlson I might have brought this one up in a different post with you but never really had a chance to properly ask the question. This post might get long with follow-up questions
My goal is t...
- 4 years ago
How about this?
GENERATE ( VALUES ( tbl[CAT] ), CALCULATETABLE ( TOPN ( 3, ADDCOLUMNS ( SUMMARIZE ( tbl, tbl[subCAT] ), "@Sum", CALCULATE ( SUM ( tbl[Value] ) ) ), [@Sum] ) ) )Or not best practice but shorter,
GENERATE ( VALUES ( tbl[CAT] ), CALCULATETABLE ( TOPN ( 3, SUMMARIZE ( tbl, tbl[subCAT], "@Sum", SUM ( tbl[Value] ) ), [@Sum] ) ) )
AlexisOlson
Super User
4 years agoHow about this?
GENERATE (
VALUES ( tbl[CAT] ),
CALCULATETABLE (
TOPN (
3,
ADDCOLUMNS (
SUMMARIZE ( tbl, tbl[subCAT] ),
"@Sum", CALCULATE ( SUM ( tbl[Value] ) )
),
[@Sum]
)
)
)
Or not best practice but shorter,
GENERATE (
VALUES ( tbl[CAT] ),
CALCULATETABLE (
TOPN (
3,
SUMMARIZE ( tbl, tbl[subCAT], "@Sum", SUM ( tbl[Value] ) ),
[@Sum]
)
)
)
- smpa014 years ago
Community Champion
AlexisOlson this is exactly what I was looking for and I don't mind taking the longer one. This is simply crazy awesome !!!!
Thanks !!!
parry2k DAX is super awesome, to say the least, and other than simply using DAX only for viz, I use it as a fully-fledged query language for my dataset published in the workspace. So for that, I don't need a measure.