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
rhcentennialh
Helper II
Helper II

Find & List Unique Values Between Two Columns

I am needing to identify and then list unique values that have been captured in Column A but not in Column B on a separate column. This appears to be a simple process but for some reason i have not found the solution.

 

Below is a simple illustration, the data set I am working with is much larger +100,000 rows

 

Column AColumn BSolution
21139986001B
125478452856
001B21134568
28561254 
4568001A 
10 REPLIES 10
Anonymous
Not applicable

You can create a new table with:

Table = 
EXCEPT( values( Table1[Column1]), values( Table1[Column2] ))

Depending on your goals, you could also just use that a table function in a measure, so that it's only called when used.

 

Also could do this in powery query 

 

I should have mentioned this previously, I generated/calculated Column A & B from a parent column (Column C).

Is there a way to show the unique values between A & B without creating tables seeing as Column A & B are calculated columns?

Anonymous
Not applicable

I dont see why not. Any chance you upload some sample data?

See below for a sample of the data and my steps as they currently are.

 

Step 1. Create two calculated

   Calculated Column 1 - List values that appear in 2018

   Calculated Column 2 - List values that appear in 2019

 

Step 2 (The Issue). How to reference the two calculated column lists to show what values have appeared in 2018 but not in 2019 yet.

 

 

Data Example:

ValueYear
B96892018
H400192018
H400192018
H400192019
J01902018
M35002018
M35002018
M35002019
M41272018
M41272019
M51362018
M85802018
N2022018
N3902018
Z00002018
Z232018
Z68232018
Z68242019
B3492018
A0842018
M255112019
M255112019
M255612019
Z12112018
W19XXXA2019
H400032019
E7822018
E7822019
M75812019
Z874422018
Z874422019
Anonymous
Not applicable

You can build a table using:

Table = 
 EXCEPT(
   SELECTCOLUMNS(
     CALCULATETABLE( Table1, FILTER( ALL( Table1), Table1[Year] = MAX( Table1[Year]))),
     "Values", CALCULATE(VALUES( Table1[Value] ))
     ),

SELECTCOLUMNS(
    CALCULATETABLE( Table1, FILTER( ALL( Table1), Table1[Year] = MAX( Table1[Year])-1)),
    "Values", CALCULATE(VALUES( Table1[Value] ))
)
 )

depending on your needs, you could use that same logic in a measure. the following with concatenate a list of records based on the year that is on the rows. So becomes a little more dynamic:

Values Not Appearing in Current Year = 
CONCATENATEX(
 EXCEPT(
   SELECTCOLUMNS(
     CALCULATETABLE( Table1, FILTER( ALL( Table1), Table1[Year] = MAX( Table1[Year])-1)),
     "Values", CALCULATE(VALUES( Table1[Value] ))
     ),

SELECTCOLUMNS(
    CALCULATETABLE( Table1, FILTER( ALL( Table1), Table1[Year] = MAX( Table1[Year]))),
    "Values", CALCULATE(VALUES( Table1[Value] ))
)
 ),
[Values],UNICHAR(10) )

Calc Table with Concatx.png

I am still having issues only showing codes that have been inputed in 2018 and not 2019

 

I am attempting to use the Table example but it will not work, i created a relationship between the two tables based on the values

 

 

Anonymous
Not applicable

I dont follow. Not sure what you are creating a relationship between. But looking at the screenshot above in the 2019 row, it's showing all the values that appeared in 2018 but not yet in 2019.  Even did this manually in excel and compared:

Calc Table with Concatx v2.png

Sorry for the vagueness I will be more specific see below, I am using the Table Option as this is the one we prefer.

 

I am receiving the following error from the equation below "The MAX function only accepts a column reference as an argument"

  
Table =
EXCEPT(
SELECTCOLUMNS(
CALCULATETABLE( 'Detail 3 0', FILTER( ALL( 'Detail 3 0'), 'Detail 3 0'[Year] = MAX( 'Detail 3 0'[Year]))),
"Values", CALCULATE(VALUES( 'Detail 3 0'[Value]))
),
SELECTCOLUMNS(
CALCULATETABLE( 'Detail 3 0', FILTER( ALL( 'Detail 3 0'), 'Detail 3 0'[Year] = MAX( 'Detail 3 0'[Year]-1))),
"Values", CALCULATE(VALUES( 'Detail 3 0'[Value] ))
)
)
 
I am sure i am misising a step somewhere
 
Also thank you for all the support so far!
 
Anonymous
Not applicable

in the second calculated table, need to enclose max before you subtract one.  Change this

SELECTCOLUMNS(
CALCULATETABLE( 'Detail 3 0', FILTER( ALL( 'Detail 3 0'), 'Detail 3 0'[Year] = MAX( 'Detail 3 0'[Year]-1))),
"Values", CALCULATE(VALUES( 'Detail 3 0'[Value] ))
)
)

to this

SELECTCOLUMNS(
CALCULATETABLE( 'Detail 3 0', FILTER( ALL( 'Detail 3 0'), 'Detail 3 0'[Year] = MAX( 'Detail 3 0'[Year])-1)),
"Values", CALCULATE(VALUES( 'Detail 3 0'[Value] ))
)
)

That fixed the error however can you clarify two questions for me

 

Question 1 - If I want to find Values that appear in 2018 and not in 2019 wouldn’t I want the first string in the EXCEPT to have "-1" after the year so it is the left side of the column while the second string is just the MAX of the year to represent the right column?

 

Question 2 - Once i made the correction to the formula you stated I get a full list of codes. However, I will want to filter this list by Name which i have various names associated with the value list and is being filtered in my first table by slicers. It appears that this new table and EXCEPT formula removes this name filter/slicer i have in place.

 

 

 

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.