Katlego
Katlego

Reputation: 51

TOPN DAX function Showing blank value in Power BI Desktop

There seems to be a problem with my DAX code:

Top Selling Prod by Quantity = CALCULATE(SELECTEDVALUE(Transactions[ITEM_ID])
,TOPN([Selected N], Transactions, [Total Quantity], DESC))

The Selected N code:

Selected N = SELECTEDVALUE('Select Top N'[Select N])

The code (Measure for Total Quantity):

Total Quantity = sum(Transactions[QTY_INVOICED])

It shows a blank value until something is selected (like a sale or a product or something like that on another visual). The thing is that I want it to show the Top 1, or Top 2 or Top 3 depending on what number is selected in the Select N Slicer. So in short, the slicer for the TOPN doesn't work and the card shows a blank value until something else is select, like a sale or product name.

Transactions Table

| ITEM_ID   | Total Quantity   
|:--------  |:---------------|
| CH15      | 25283          |   
| CH16      | 25006          |
| CH17      | 18505          |
| CH18      | 18440          |  
| CH37      | 17599          |  

I want the card visual to show the top selling item (Item_ID) by Total Quantity based on the selected value on the slicer:

The Expected Result Result is :

-------
|CH15 |
-------

Displayed on a card visual

Upvotes: 0

Views: 496

Answers (1)

Jos Woolley
Jos Woolley

Reputation: 9062

You'd need something like:

=TOPN (
    1,
    TOPN (
        [Selected N],
        VALUES ( Transactions[ITEM_ID] ),
        [Total Quantity], DESC
    )
)

Upvotes: 1

Related Questions