Advance your Data & AI career with 50 days of live learning, dataviz contests, hands-on challenges, study groups & certifications and more!
Get registeredJoin us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM. Register now.
Hi guys,
I have some m-code which looks like the below...
The LegalEntity function parameter is optional. If this parameter is not filled in when the function is invoked (i.e. it is null), I would like PQ to basically 'skip' the "// Filter by legal entity (DataAreaId)" step and not filter the table. If the parameter is filled in (i.e. not null) I would like the table to be filtered. Any ideas?
Thank you in advance!! 🙂
(SourceTable as table, TableName as text, optional LegalEntity as text)=>
let
// Set variables
Source = SourceTable,
// Change headers to uppercase
UppercaseHeaders = Table.TransformColumnNames(Source,Text.Upper),
// Filter by ModifiedDateTime
#"Change ModifiedDateTime to Date type" = Table.TransformColumnTypes(UppercaseHeaders,{{"MODIFIEDDATETIME", type date}}),
#"Filter by ModifiedDateTime" = Table.SelectRows(#"Change ModifiedDateTime to Date type", each [MODIFIEDDATETIME] > (Date.AddDays(Date.From(DateTime.LocalNow()),-NumOfDaysSinceLastDataRefresh))),
// Filter by legal entity (DataAreaId)
#"Filter by legal entity" = each if LegalEntity = null then #"Filter by ModifiedDateTime" else (Table.SelectRows(#"Filter by ModifiedDateTime", each [DATAAREAID] = LegalEntity)),
{...more code....}
Solved! Go to Solution.
Hi all,
I have managed to get this working...
(SourceTable as table, TableName as text, optional LegalEntity as text)=>
let
// Set variables
Source = SourceTable,
// Change headers to uppercase
UppercaseHeaders = Table.TransformColumnNames(Source,Text.Upper),
// Filter by ModifiedDateTime
#"Change ModifiedDateTime to Date type" = Table.TransformColumnTypes(UppercaseHeaders,{{"MODIFIEDDATETIME", type date}}),
#"Filter by ModifiedDateTime" = Table.SelectRows(#"Change ModifiedDateTime to Date type", each [MODIFIEDDATETIME] > (Date.AddDays(Date.From(DateTime.LocalNow()),-NumOfDaysSinceLastDataRefresh))),
// If LegalEntity is not null then filter by legal entity (DataAreaId)
#"Filter by legal entity" = if LegalEntity <> null then Table.SelectRows(#"Filter by ModifiedDateTime", each [DATAAREAID] = LegalEntity) else UppercaseHeaders,
Hi all,
I have managed to get this working...
(SourceTable as table, TableName as text, optional LegalEntity as text)=>
let
// Set variables
Source = SourceTable,
// Change headers to uppercase
UppercaseHeaders = Table.TransformColumnNames(Source,Text.Upper),
// Filter by ModifiedDateTime
#"Change ModifiedDateTime to Date type" = Table.TransformColumnTypes(UppercaseHeaders,{{"MODIFIEDDATETIME", type date}}),
#"Filter by ModifiedDateTime" = Table.SelectRows(#"Change ModifiedDateTime to Date type", each [MODIFIEDDATETIME] > (Date.AddDays(Date.From(DateTime.LocalNow()),-NumOfDaysSinceLastDataRefresh))),
// If LegalEntity is not null then filter by legal entity (DataAreaId)
#"Filter by legal entity" = if LegalEntity <> null then Table.SelectRows(#"Filter by ModifiedDateTime", each [DATAAREAID] = LegalEntity) else UppercaseHeaders,
Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!
Check out the October 2025 Power BI update to learn about new features.