Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

Filter one column by value, create unique list and compare with another column to find non-matching

Hello,

 

I have the following table with submissions sent every week (by week number) by a group of people who send their individual scores.

 

Week NumberNameSubmitted Score
42Anahi Johns58
42Anahi Johns38
42Max Gilbert43
43Trenton Espinoza62
43Trenton Espinoza30
44Max Gilbert78

 

And this is the reference list of all names who should submit their scores every week:

 

Reference List of names
Anahi Johns
Trenton Espinoza
Max Gilbert

 

I am trying to create a new table in Power Query that contains the list of names (compared to the reference list of names) who have not submitted by week number. Notice that for any week number, the same person can submit their scores more than one time.

 

The new table should have two columns. For example, considering the two tables above, the result should be:

 

Week NumberName
42Trenton Espinoza
43Anahi Johns
43Max Gilbert
44Anahi Johns
44Trenton Espinoza

 

Both tables are dynamic since the rows are being added at any time, so the result should always recalculate to show the actual results.

 

Any help is much appreciated!!

  • I will assume your two tables are named Reference and Submissions.

     

    Create a copy of your Reference table and add a custom column defined as 

    {List.Min(Submissions[Week Number])..List.Max(Submissions[Week Number])}

    Expand this column to new rows to get a full cross product of names and weeks.

     

    Then do a left anti-join merge with the Submissions table matching on both the Name and Week Number columns.

    Remove the extra column of nulls.

     

    Full code:

    let
        Source = Reference,
        #"Added Custom" = Table.AddColumn(Reference, "Week Number", each {List.Min(Submissions[Week Number])..List.Max(Submissions[Week Number])}),
        #"Expanded Week Number" = Table.ExpandListColumn(#"Added Custom", "Week Number"),
        #"Merged Queries" = Table.NestedJoin(#"Expanded Week Number", {"Name", "Week Number"}, Submissions, {"Name", "Week Number"}, "Submissions", JoinKind.LeftAnti),
        #"Removed Columns" = Table.RemoveColumns(#"Merged Queries",{"Submissions"})
    in
        #"Removed Columns"

5 Replies

  • I will assume your two tables are named Reference and Submissions.

     

    Create a copy of your Reference table and add a custom column defined as 

    {List.Min(Submissions[Week Number])..List.Max(Submissions[Week Number])}

    Expand this column to new rows to get a full cross product of names and weeks.

     

    Then do a left anti-join merge with the Submissions table matching on both the Name and Week Number columns.

    Remove the extra column of nulls.

     

    Full code:

    let
        Source = Reference,
        #"Added Custom" = Table.AddColumn(Reference, "Week Number", each {List.Min(Submissions[Week Number])..List.Max(Submissions[Week Number])}),
        #"Expanded Week Number" = Table.ExpandListColumn(#"Added Custom", "Week Number"),
        #"Merged Queries" = Table.NestedJoin(#"Expanded Week Number", {"Name", "Week Number"}, Submissions, {"Name", "Week Number"}, "Submissions", JoinKind.LeftAnti),
        #"Removed Columns" = Table.RemoveColumns(#"Merged Queries",{"Submissions"})
    in
        #"Removed Columns"
  • Anonymous's avatar
    Anonymous
    Not applicable

    AlexisOlson Thanks!

     

    But i have another question based on the same resulting merged table. So, this is the result of the merged table, named: No Match Names

     

    NameWeek Number
    Trenton Espinoza42
    Anahi Johns43
    Max Gilbert43
    Anahi Johns44
    Trenton Espinoza44


    How do i compare this merged table above with another table named
    Exception Names (as below) by Name and Week Number and highlight the Names in the No Match Names table which are missing or not common for that Week Number (highlight font in red) or common for the same Week Number but based on the condition that the Week Number in the Exception Names table below should be equal to the Week Number in the No Match Names table (highlight font in orange).

     

    NameWeek Number
    Jadyn Levine43
    Trenton Espinoza41
    Anahi Johns43
    Katherine Waters45
    Trenton Espinoza43
    Jazlynn Mcclure46
    Anahi Johns47
    Everett Lang42
    Anahi Johns44

     

    My guess is that this could be done in Power Query or DAX but i am new to both and i don't know which is the best way. But as of now, i have these two tables in Power BI in two table visualizations.

    • AlexisOlson's avatar
      AlexisOlson
      Super User

      I don't quite follow. What do you expect the result to be?

      • Anonymous's avatar
        Anonymous
        Not applicable

        I have these two tables (both in Power Query) and displayed in Power BI as two Table visualizations:

         

        Table name: Submissions

         

        NameWeek Number
        Trenton Espinoza42
        Anahi Johns43
        Max Gilbert43
        Jadyn Levine44

         

        Table name: Exceptions

         

        NameWeek Number
        Jadyn Levine43
        Trenton Espinoza41
        Anahi Johns43
        Katherine Waters45
        Jazlynn Mcclure46

         

        In Power BI, i want the result to be shown in the Table Submissions by highlighting the names based on certain conditions.

         

        Result shown in Power BI in the Table Submissions:

         

        NameWeek Number
        Trenton Espinoza42
        Anahi Johns43
        Max Gilbert43
        Jadyn Levine44

         

        The conditions for highlighting the names in the table Submissions:

        1. The names in the Submissions table not in common with the names in the Exceptions table, highlight in red.

        2. If the names in the Submissions table is common with the names in the Exceptions table, then check if the Week Number in the Submissions table is less than the Week Number in the Exceptions table. If no, then highlight in red.

         

        But i would like this to colour change in the table visualization in the Power BI report.