Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Sharma0815
Helper II
Helper II

Comparing column values and ignoring the order of element DAX

Hi All,

 

I have a column where I need to check whether the column value contains the same data in any order.
I want to get the first value as output value if the value matches in any order.

 

Can we do this using DAX ??

 

Example.

 

Combo codeOutput
1059-0,1056-11059-0,1056-1
1056-1,1059-01059-0,1056-1
312-0,313-1,314-2312-0,313-1,314-2
314-2,313-1,312-0312-0,313-1,314-2
2 REPLIES 2
CNENFRNL
Community Champion
Community Champion

Yes, DAX does the trick easily with some simple transformation of original dataset,

Screenshot 2021-08-31 204549.png

 

As to me, PQ solution is more straightforward and comprehensible.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQwtdQ10AFSZrqGSrE6YBEgUwciAROBMY0NjYCqjQ2NgSqMDU10jTC0OELVAeXg6oyQdAP5RoYgfiwA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Combo code" = _t]),
    #"Added Custom" = Table.AddColumn(Source, "Codes", each Text.Combine(List.Sort(Text.Split([Combo code], ",")),",")),
    #"Grouped Rows" = Table.Group(#"Added Custom", {"Codes"}, {{"ar", each _, type table [Combo code=nullable text, Codes=text]}}),
    #"Expanded ar" = Table.ExpandTableColumn(#"Grouped Rows", "ar", {"Combo code"}, {"Combo code"})
in
    #"Expanded ar"

Screenshot 2021-08-31 204941.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

wdx223_Daniel
Super User
Super User

Output = 
VAR _tbl =
    ADDCOLUMNS (
        ALL ( SampleTable[Combo Code] ),
        "@new",
            VAR _p =
                SUBSTITUTE ( 'SampleTable'[Combo Code], ",", "|" )
            VAR _len =
                PATHLENGTH ( _p )
            VAR _series =
                GENERATESERIES ( 1, _len )
            VAR _items =
                ADDCOLUMNS ( _series, "@item", PATHITEM ( _p, [Value] ) )
            VAR _items_with_idx =
                ADDCOLUMNS (
                    _items,
                    "@idx", COUNTROWS ( FILTER ( _items, [@item] <= EARLIER ( [@item] ) ) )
                )
            RETURN
                CONCATENATEX (
                    _series,
                    MAXX (
                        TOPN (
                            1,
                            FILTER ( _items_with_idx, [@idx] >= EARLIER ( [Value] ) ),
                            [@idx], ASC
                        ),
                        [@item]
                    ),
                    ","
                )
    )
RETURN
    MINX (
        FILTER (
            _tbl,
            'SampleTable'[Combo Code] = SELECTEDVALUE ( SampleTable[Combo Code] )
        ),
        [@new]
    )

wdx223_Daniel_0-1630381673114.png

 

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.