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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
smpa01
Super User
Super User

Seeking Explanation of Comparer.OrdinalIgnoreCase

I am trying to understand how comparer-ordinalignorecase works. I have run the following test.

 

= #table({"col1"},{
{Comparer.OrdinalIgnoreCase("Abc", "abc")}/*row#=1*/,{Comparer.OrdinalIgnoreCase("Abc", "cab")}/*row#==2*/,{Comparer.OrdinalIgnoreCase("Abc", "xya")}/*row#==3*/,
{Comparer.OrdinalIgnoreCase("Abc", "efg")}/*row#==4*/,{Comparer.OrdinalIgnoreCase("Abc", "")}/*row#==5*/,{Comparer.OrdinalIgnoreCase("Abc", "0")}/*row#==6*/,
{Comparer.OrdinalIgnoreCase("Abc", "ABC")}/*row#==7*/,{Comparer.OrdinalIgnoreCase("Abc", "unknown")}/*row#==8*/,{Comparer.OrdinalIgnoreCase("Abc", "#")}/*row#==9*/
})

 

 

smpa01_2-1663259652938.png

I understand that they return 0 on the exact match (row#1 and 7) but how do I know when they return -1 and +1? I can't seem to understand what it returns in what circumstances.

 

The official doc says the following but what exactly are Ordinal rules to compare the provided values x and y.

 

smpa01_3-1663259778145.png

 

I want to utilize this in production, once I fully understand the behaviour.

 

I expected this to return 0 for row 1 and row 7 and a different value (either 1 or -1) for other rows. But why does it return 3 values? Are there more values that can be returned by the function that I currently don't know of?

@ImkeF @AlexisOlson 

 

 

Thank you in advance.

 

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs
1 ACCEPTED SOLUTION
AlexisOlson
Super User
Super User

The word "ordinal" usually means there is some sort of order involved. For any two objects A and B, there are three possible options when you compare them: A > B, A = B, A < B which correspond to 1, 0, and -1 for this comparer.

 

You can achieve the same thing as follows:

let
  Source = #table(
    type table [col1 = text, col2 = text], 
    {
      {"Abc", "abc"},     /*row#==1*/
      {"Abc", "cab"},     /*row#==2*/
      {"Abc", "xya"},     /*row#==3*/
      {"Abc", "efg"},     /*row#==4*/
      {"Abc", ""},        /*row#==5*/
      {"Abc", "0"},       /*row#==6*/
      {"Abc", "ABC"},     /*row#==7*/
      {"Abc", "unknown"}, /*row#==8*/
      {"Abc", "#"}        /*row#==9*/           
    }
  ),
    #"Added Custom" = Table.AddColumn(Source, "Compare", each
      if      Text.Lower([col1]) > Text.Lower([col2]) then  1
      else if Text.Lower([col1]) < Text.Lower([col2]) then -1
      else 0
    ,Int64.Type)
in
  #"Added Custom"

AlexisOlson_0-1663276094204.png

The ordering is alphanumeric ignoring case.

View solution in original post

1 REPLY 1
AlexisOlson
Super User
Super User

The word "ordinal" usually means there is some sort of order involved. For any two objects A and B, there are three possible options when you compare them: A > B, A = B, A < B which correspond to 1, 0, and -1 for this comparer.

 

You can achieve the same thing as follows:

let
  Source = #table(
    type table [col1 = text, col2 = text], 
    {
      {"Abc", "abc"},     /*row#==1*/
      {"Abc", "cab"},     /*row#==2*/
      {"Abc", "xya"},     /*row#==3*/
      {"Abc", "efg"},     /*row#==4*/
      {"Abc", ""},        /*row#==5*/
      {"Abc", "0"},       /*row#==6*/
      {"Abc", "ABC"},     /*row#==7*/
      {"Abc", "unknown"}, /*row#==8*/
      {"Abc", "#"}        /*row#==9*/           
    }
  ),
    #"Added Custom" = Table.AddColumn(Source, "Compare", each
      if      Text.Lower([col1]) > Text.Lower([col2]) then  1
      else if Text.Lower([col1]) < Text.Lower([col2]) then -1
      else 0
    ,Int64.Type)
in
  #"Added Custom"

AlexisOlson_0-1663276094204.png

The ordering is alphanumeric ignoring case.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors
Top Kudoed Authors