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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
Sam_BI_Analyst
Frequent Visitor

Dax Query to find Missing Items from a List

Hello Community,

 

I need help with finding missing items from a list of items, Below is my dataset and problem.

 

I have students dataset and i want to find the missing subjects for each student,

 

Student Data - 

Sam_BI_Analyst_2-1720811405955.png

 

 

Subjects Table-

Sam_BI_Analyst_1-1720811070010.png

 

Requirement - I want to find the missing subjects for each student, Let's take Lyon for instance, Lyon had registered only one subject (Maths), Now i want to find he missing subjects for him from the subjects table i.e., Science, english, biology, physics.

 

My Result dataset should be,

Sam_BI_Analyst_3-1720811513178.png

 

How do i achieve the above result in power bi? Any suggestions would be appreciated.

 

 

2 ACCEPTED SOLUTIONS
ThxAlot
Super User
Super User

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUQpOztRRcM1L11EIyKhUitWJVjICivomlmToKDhl5oNFjCHqwGwTJD1gAVOocqXYWAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, Subjects = _t]),
    Subject = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCk7OVIrViVbyTSzJADNc89LBtFNmPpgOyKhUio0FAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Subject = _t]),

    #"Added Column Missing" = let s = Subject[Subject] in Table.AddColumn(Source, "Missing", each let l = List.Transform(Text.Split([Subjects],","), Text.Trim) in Text.Combine(List.Difference(s, l), ", "))
in
    #"Added Column Missing"

ThxAlot_0-1720815067710.png



Expertise = List.Accumulate(


        {Days as from Today},


        {Skills and Knowledge},


        (Current, Everyday) => Current & Day.LeanAndPractise(Everyday)


)



View solution in original post

Ritaf1983
Super User
Super User

Hi @Sam_BI_Analyst 
You can achieve the desired results with those steps :
1. From PQ split the table of registered :

Ritaf1983_0-1720873863244.png

The result that you should get is :

Ritaf1983_1-1720873913121.png

2. create a relationship between this table the subjects table :

Ritaf1983_2-1720873977517.pngRitaf1983_3-1720873992314.png

3. Create 2 Measures :

Registered = CONCATENATEX('Table','Table'[Subjects Registered],",")
Missing =
var _registered = values('Table'[Subjects Registered])
var _allsubjects = all('Subjects'[Subjects])
RETURN
CONCATENATEX(EXCEPT(_allsubjects,_registered),Subjects[Subjects],",")
Result :
Ritaf1983_4-1720874092714.png

PBIX is attached

If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly.

 

Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile

View solution in original post

3 REPLIES 3
Ritaf1983
Super User
Super User

Hi @Sam_BI_Analyst 
You can achieve the desired results with those steps :
1. From PQ split the table of registered :

Ritaf1983_0-1720873863244.png

The result that you should get is :

Ritaf1983_1-1720873913121.png

2. create a relationship between this table the subjects table :

Ritaf1983_2-1720873977517.pngRitaf1983_3-1720873992314.png

3. Create 2 Measures :

Registered = CONCATENATEX('Table','Table'[Subjects Registered],",")
Missing =
var _registered = values('Table'[Subjects Registered])
var _allsubjects = all('Subjects'[Subjects])
RETURN
CONCATENATEX(EXCEPT(_allsubjects,_registered),Subjects[Subjects],",")
Result :
Ritaf1983_4-1720874092714.png

PBIX is attached

If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly.

 

Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile
ThxAlot
Super User
Super User

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUQpOztRRcM1L11EIyKhUitWJVjICivomlmToKDhl5oNFjCHqwGwTJD1gAVOocqXYWAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, Subjects = _t]),
    Subject = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCk7OVIrViVbyTSzJADNc89LBtFNmPpgOyKhUio0FAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Subject = _t]),

    #"Added Column Missing" = let s = Subject[Subject] in Table.AddColumn(Source, "Missing", each let l = List.Transform(Text.Split([Subjects],","), Text.Trim) in Text.Combine(List.Difference(s, l), ", "))
in
    #"Added Column Missing"

ThxAlot_0-1720815067710.png



Expertise = List.Accumulate(


        {Days as from Today},


        {Skills and Knowledge},


        (Current, Everyday) => Current & Day.LeanAndPractise(Everyday)


)



Can you explain what did you do for add column in the end

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

Feb2025 NL Carousel

Fabric Community Update - February 2025

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