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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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
Memorable Member
Memorable Member

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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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