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] ) ) )
parry2k
Super User
4 years agosmpa01 try this measure
Top 3 =
CALCULATE (
[Sum],
KEEPFILTERS (
TOPN (
3,
FILTER (
ALLSELECTED (
tbl[CAT],
tbl[SubCat] ),
tbl[CAT] = MAX ( tbl[CAT] )
),
[Sum],
DESC
)
)
)
✨ Follow us on LinkedIn and to our YouTube channel
Learn about conditional formatting at Microsoft Reactor
My latest blog post The Power of Using Calculation Groups with Inactive Relationships (Part 1) (perytus.com) I would ❤ Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!
⚡ Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.