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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Simon_Evans
Helper I
Helper I

M Code for a DAX expression

Hi Everyone

I need to convert or know how to write the following DAX Add Column in M

 

Exclude = IF(SessionAttendanceLeavers[DateOfLeaving] < LOOKUPVALUE(AcademicYears[Start Date],AcademicYears[Term],"Autumn"),"Remove","Keep")
 
The above works totally fine but I need to be able to add this column as an Applied Step in Transform Data so that I can apply a filter as a following step to remove certain rows from the table. 
 
SessionAttendanceLeavers and AcademicYears are 2 un-related tables.
 
Does anyone know how I can create this in M Code please?
1 ACCEPTED SOLUTION

Hi, @Simon_Evans 
Thanks for the data, it always helps so much:
Add this as a new Custom Column:

let
dateofleaving = [DateofLeaving],
matchingTerm = Table.SelectRows(AcademicYears, each dateofleaving > _[Start Date] and _[Season] = "Autumn")
in
if not(Table.IsEmpty(matchingTerm)) then "Keep" else "Remove"

vojtechsima_0-1650885651314.png

Please note, I had to adjust your custom data and I had to add type of Season so I was able to retrieve the needed information.
I attached the file, I worked with.

View solution in original post

4 REPLIES 4
vojtechsima
Super User
Super User

Hi, @Simon_Evans 
Please share sample data for each table so I can play with the data and give you results. Thanks

Something like this for each table:
IdDateUserId

1 01.01.2022 2
2 27.01.2022 1
3 02.02.2022 2
4 20.03.2022 7

Hi @vojtechsima 

Apologies for the delay. Please see the example I have put together below.

 

SessionAttendanceLeavers table example

AttendanceCodeStudentIDDateofLeavingEmployee
A1329183376A9221402423/07/2021null
A1161584171A9221402423/07/2021null
A1161584171A35296371010/10/2021null
A930902628A35296371010/10/2021null
A1329183376A18401014011/1/2022null

 

AcademicYears table

TypeStart DateEnd Date
Term01/09/202117/12/2021
Term04/01/202201/04/2022
Term19/04/202222/07/2022

 

Hi, @Simon_Evans 
Thanks for the data, it always helps so much:
Add this as a new Custom Column:

let
dateofleaving = [DateofLeaving],
matchingTerm = Table.SelectRows(AcademicYears, each dateofleaving > _[Start Date] and _[Season] = "Autumn")
in
if not(Table.IsEmpty(matchingTerm)) then "Keep" else "Remove"

vojtechsima_0-1650885651314.png

Please note, I had to adjust your custom data and I had to add type of Season so I was able to retrieve the needed information.
I attached the file, I worked with.

Thank you so much, that is perfect!

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! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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