Rhea
Rhea

Reputation: 53

How to use ORDER BY in Power BI DAX

I have a DAX which concatenates values from one column in my data.

I want to rank my data by 2 columns right inside my DAX as its concatenating rows randomly.

How can I achieve that?


My data looks like -

enter image description here


Now, the problem is that I've sorted by id... But I want to sort by "id" and "name" so that it concatenates data in the same manner.

Currently, it's concatenating for one id as a/b/c and for another id as b/a/c


My DAX looks like this -

=
VAR ThisID = 'Table'[id]
RETURN
    CONCATENATEX(
        FILTER(
            'Table',
            'Table'[id] = ThisID
        ),
        'Table'[likes],
        "/"
    )

I tried using 'ORDER BY' with the EVALUATE. But, that's giving ERROR.

Upvotes: 2

Views: 1358

Answers (1)

Jos Woolley
Jos Woolley

Reputation: 9062

Just add the name column as one of CONCATENATEX's orderBy_expression parameters:

=
VAR ThisID = 'Table'[id]
RETURN
    CONCATENATEX(
        FILTER(
            'Table',
            'Table'[id] = ThisID
        ),
        'Table'[likes],
        "/",
        'Table'[name]
    )

Upvotes: 2

Related Questions