Forum Discussion
Column filtering with the result of another request
- 1 year ago
Make sure you have a relationship defined between Employees and Courses table. Something like:
If you just want a visual of Employee columns where they have zero related courses, then the simplest (but not best practice) way would be to
- Add an implicit count measure from your Courses table
- set the filter in the filter pane of the implicit measure to 'is blank'
- remove the implicit measure
Here is a quick gif showing these steps (note, I just added a Year column to my Courses table, but best practice would be to create a Date table):
If you mean that you need the DAX to craft a virtual table of Employees with zero related courses in any filter context (like, when Year = 2022), to then use further on in your measure/column, then you would use something like the below. This is an example measure where we count the rows of Employees with no related courses:
Missing Courses Count = CALCULATE( COUNTROWS( Employees ), // The below filter gets us rows of Employees where we can't find any related Courses rows FILTER( Employees, CALCULATE( ISEMPTY( Courses ) ) ) ) - 1 year ago
How would this work for you?
Employees:Course Attendance with a custum column to get the year = Table.AddColumn(Attendance, "Attendance Year", each Date.Year([Date])):
Producing for all years, the Employees not attending any course:
Using this query:
let Source = Attendance, // First group all attending employees by year #"Grouped Rows" = Table.Group(Source, {"Attendance Year"}, {{"Year Attendance", each _, type table}}), // for each row do a right anti join on ID, with the employee table, getting the employees not attending in that year. #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Year Non Attendance", each Table.NestedJoin([Year Attendance],"ID",Employee,"ID","Not Attended",JoinKind.RightAnti)), // Get the joind Employees as a table #"Expanded Year Non Attendance" = Table.ExpandTableColumn(#"Added Custom", "Year Non Attendance", {"Not Attended"}, {"Not Attended"}), // Replace the result of the join with the actual ID's (expanding each row in multiple rows) #"Expanded Not Attended" = Table.ExpandTableColumn(#"Expanded Year Non Attendance", "Not Attended", {"ID"}, {"ID"}), // Remove helper columns #"Removed Columns" = Table.RemoveColumns(#"Expanded Not Attended",{"Year Attendance"}), // Sort by Year and ID #"Sorted Rows" = Table.Sort(#"Removed Columns",{{"Attendance Year", Order.Ascending}, {"ID", Order.Ascending}}) in #"Sorted Rows"
Did I answer your question? Then please (also) mark my post as a solution and make it easier to find for others having a similar problem.
Remember: You can mark multiple answers as a solution...
If I helped you, please click on the Thumbs Up to give Kudos.Kees Stolker
A big fan of Power Query and Excel
Make sure you have a relationship defined between Employees and Courses table. Something like:
If you just want a visual of Employee columns where they have zero related courses, then the simplest (but not best practice) way would be to
- Add an implicit count measure from your Courses table
- set the filter in the filter pane of the implicit measure to 'is blank'
- remove the implicit measure
Here is a quick gif showing these steps (note, I just added a Year column to my Courses table, but best practice would be to create a Date table):
If you mean that you need the DAX to craft a virtual table of Employees with zero related courses in any filter context (like, when Year = 2022), to then use further on in your measure/column, then you would use something like the below. This is an example measure where we count the rows of Employees with no related courses:
Missing Courses Count =
CALCULATE(
COUNTROWS( Employees ),
// The below filter gets us rows of Employees where we can't find any related Courses rows
FILTER( Employees, CALCULATE( ISEMPTY( Courses ) ) )
)