Forum Discussion
Variable Top N depending on Column Conditions
- Anonymous4 years ago
Thanks Hariharan_R. This measure is absolutely correct. But i have one more doubt for the same.
How to show multiple Categories in this DAX where i need this condition of variable Top N . For eg,
I have Category D and E as well along with C where this filteration of top N is different as compared to Category A and B.
Thanks.
- 4 years ago
Hi,
If you have more values then try use disconnected table with the TOPN values otherwise try the below one.
Top 3 = VAR _N = SWITCH(TRUE(), MIN('Table'[Category])="C",2,MIN('Table'[Category])="D",1,MIN('Table'[Category])="E",1,3) VAR Top3 = CALCULATETABLE ( GENERATE ( VALUES ('Table'[Category] ), TOPN ( _N, CALCULATETABLE ( VALUES ('Table'[Brand] ) ), [Sales] ) ), ALLSELECTED() ) RETURN CALCULATE ( 1 * ( NOT ISEMPTY ( 'Table' ) ), KEEPFILTERS ( Top3 ) )Thanks
Hari
Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.
My Blog :: YouTube Channel :: My Linkedin
Hi,
If you have more values then try use disconnected table with the TOPN values otherwise try the below one.
Top 3 =
VAR _N =
SWITCH(TRUE(), MIN('Table'[Category])="C",2,MIN('Table'[Category])="D",1,MIN('Table'[Category])="E",1,3)
VAR Top3 =
CALCULATETABLE (
GENERATE (
VALUES ('Table'[Category] ),
TOPN (
_N,
CALCULATETABLE ( VALUES ('Table'[Brand] ) ),
[Sales]
)
),
ALLSELECTED()
)
RETURN
CALCULATE (
1 * ( NOT ISEMPTY ( 'Table' ) ),
KEEPFILTERS ( Top3 )
)
Thanks
Hari
If I helped you, click on the Thumbs Up to give Kudos.
My Blog :: YouTube Channel :: My Linkedin
your dax function is working fine but i have the categories 6(a,b,c,d,e,f) for each category top 5 brands i want baced on total sales
- Hariharan_R4 years agoSolution Sage
Hi Anonymous
You can remove _N with 5 like below.
CALCULATETABLE ( GENERATE ( VALUES ('Table'[Category] ), TOPN ( 5, CALCULATETABLE ( VALUES ('Table'[Brand] ) ), [Sales] ) ), ALLSELECTED() ) RETURN CALCULATE ( 1 * ( NOT ISEMPTY ( 'Table' ) ), KEEPFILTERS ( Top3 ) )Thanks
Hari
Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.
My Blog :: YouTube Channel :: My Linkedin