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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
Anonymous
Not applicable

filter problem

I have an issue with Power Query in Power BI desktop where I'm losing records.  When troubleshooting I discovered that if I apply a step to filter missing student X by their ID, the record is displayed, such as:

 

Term = 202002

Student ID = 99999999

Effective Term = 201801

Include = Yes

 

However, if I apply a filter to include all students where Include = Yes without first filtering for just that student, that student is lost while others are included.  If it makes a difference (can't see why it should) the Include field is conditional based on Effective Term <= Term.  For this particular report I'm retaining 18,044 records while losing 4 records that should also be retained.  

 

I'm hoping that somebody can help because this is driving me absolutely bonkers!

1 ACCEPTED SOLUTION
Anonymous
Not applicable

I've stumbled upon something that seems to have resolved the problem.  The report was pulling information from a table which had an effective term for student records.  You have to pull the maximum effective term prior to or equal to the term being reported so that student data for that term is correct.  I filtered that table and discovered three values that could not be correct - "000000", "210003", and "999999".  I filtered out all of those values.  Even though none of the students I was losing had records with those bad entries, the act of removing them allowed all data for all students to be retrieved.

 

I wish I understood the "why" behind all of this, but until then I'll apply what I've learned to all the reports I build using that table.

View solution in original post

3 REPLIES 3
Greg_Deckler
Community Champion
Community Champion

Can you post your code from Advanced Editor?



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

The code is below.  If I search for the problematic ID (column named Pidm) before the step highlighted in red and bold, it shows up with an Include value of "Yes".  After the highlighted step which filters to include only records with "Yes", it is gone.  If I filter for just that ID before the highlighted step - so that it is the only row left - it is maintained through the rest of the steps.  I have identified two separate IDs that are being dropped through this process.

 

let
Source = #"SATURN SFRSTCR",
#"Removed Other Columns" = Table.SelectColumns(Source,{"TermCode", "Pidm"}),
#"Removed Duplicates" = Table.Distinct(#"Removed Other Columns"),
#"Inserted Merged Column" = Table.AddColumn(#"Removed Duplicates", "TermPidm", each Text.Combine({[TermCode], Text.From([Pidm], "en-US")}, ""), type text),
#"Merged Queries" = Table.NestedJoin(#"Inserted Merged Column", {"Pidm"}, #"SATURN SGBSTDN", {"Pidm"}, "SATURN SGBSTDN", JoinKind.LeftOuter),
#"Expanded SATURN SGBSTDN" = Table.ExpandTableColumn(#"Merged Queries", "SATURN SGBSTDN", {"EffTerm"}, {"EffTerm"}),
#"Added Conditional Include" = Table.AddColumn(#"Expanded SATURN SGBSTDN", "Include", each if [EffTerm] <= [TermCode] then "Yes" else "No"),
#"Filtered Rows Include" = Table.SelectRows(#"Added Conditional Include", each ([Include] = "Yes")),
#"Grouped Rows" = Table.Group(#"Filtered Rows Include", {"TermCode", "Pidm", "TermPidm"}, {{"MaxEffTerm", each List.Max([EffTerm]), type text}}),
#"Merged Queries1" = Table.NestedJoin(#"Grouped Rows", {"Pidm", "MaxEffTerm"}, #"SATURN SGBSTDN", {"Pidm", "EffTerm"}, "SATURN SGBSTDN", JoinKind.LeftOuter),
#"Expanded SATURN SGBSTDN1" = Table.ExpandTableColumn(#"Merged Queries1", "SATURN SGBSTDN", {"Styp", "Resd"}, {"Styp", "Resd"}),
#"Removed Columns" = Table.RemoveColumns(#"Expanded SATURN SGBSTDN1",{"MaxEffTerm"})
in
#"Removed Columns"

Anonymous
Not applicable

I've stumbled upon something that seems to have resolved the problem.  The report was pulling information from a table which had an effective term for student records.  You have to pull the maximum effective term prior to or equal to the term being reported so that student data for that term is correct.  I filtered that table and discovered three values that could not be correct - "000000", "210003", and "999999".  I filtered out all of those values.  Even though none of the students I was losing had records with those bad entries, the act of removing them allowed all data for all students to be retrieved.

 

I wish I understood the "why" behind all of this, but until then I'll apply what I've learned to all the reports I build using that table.

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

July Power BI Update Carousel

Power BI Monthly Update - July 2026

Check out the July 2026 Power BI update to learn about new features.

60 days of Data Days Carousel

Data Days 2026

Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.