Forum Discussion
rauldip22
8 years agoFrequent Visitor
How to select a top filtered value from a table with DAX
Hello!
I need a DAX consult to select a Gender with the max Amount from my table filtered by a Category.
With SQL ir should be: SELECT TOP 1 Gender FROM TableName WHERE Category = "A" ORDER BY Amount.
My Table is:
| Gender | Amount | Category | Cases |
| Male | 6768768 | A | 6 |
| Male | 344 | B | 8 |
| Male | 44442 | C | 6 |
| Male | 3344 | D | 5 |
| Female | 7656 | A | 4 |
| Female | 44577 | B | 3 |
| Female | 334442 | C | 6 |
| Female | 455 | D | 5 |
Thanks!!!!
Or you can hardcode it for Category A as follows
Measure 2 = TOPN ( 1, VALUES ( TableName[Gender] ), CALCULATE ( SUM ( TableName[Amount] ), TableName[Category] = "A" ), DESC )
3 Replies
- Zubair_Muhammad
Community Champion
Hi rauldip22
Try this MEASURE...It will give you the Gender with Highest Amount according to category or cases that you select
Measure = TOPN ( 1, VALUES ( TableName[Gender] ), CALCULATE ( SUM ( TableName[Amount] ) ), DESC )- Zubair_Muhammad
Community Champion
Or you can hardcode it for Category A as follows
Measure 2 = TOPN ( 1, VALUES ( TableName[Gender] ), CALCULATE ( SUM ( TableName[Amount] ), TableName[Category] = "A" ), DESC )- rauldip22Frequent Visitor
Thanks!!! It Works!