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

Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM. Register now.

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
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.