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
Anonymous
Not applicable

If function parameter is null then skip step

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....}

1 ACCEPTED SOLUTION
Anonymous
Not applicable

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,

View solution in original post

1 REPLY 1
Anonymous
Not applicable

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,

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.

Top Solution Authors
Top Kudoed Authors