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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
BNiddrieDavies
Regular Visitor

We cannot convert a value of type Function to type Logical IF function

Hello

I am trying to put a "List.AnyTrue" function inside an "if" function, but dont know the correct syntax. In the example below, i want to put "addedCustom1" inside "addedCustom"...which i have tried to do.... but this comes back with "We cannot convert a value of type Function to type Logical".

Any help greatly appreciated.

Thank you

 

Ben

 

let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Je Header Id", Int64.Type}, {"Description", type text}, {"Total", Int64.Type}}),
#"Added Custom" = Table.AddColumn(#"Changed Type", "Basic Pay1", each if (F1)=> List.AnyTrue(List.Transform(Basic,each Text.Contains(F1[Description], _))) = true then [Total] else 0),
#"Added Custom1" = Table.AddColumn(#"Added Custom", "Basic Pay 2", each if [Basic Pay1] = true then [Total] else 0)
in
#"Added Custom1"

1 ACCEPTED SOLUTION
artemus
Microsoft Employee
Microsoft Employee

change

each if (F1)=>

to

(F1) => if

View solution in original post

5 REPLIES 5
BNiddrieDavies
Regular Visitor

Just to confirm for other users: formula is now written like the below and works thanks to @artemus :

 

Formula is now written like:
let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Je Header Id", Int64.Type}, {"Description", type text}, {"Total", Int64.Type}}),
#"Added Custom" = Table.AddColumn(#"Changed Type", "Basic Pay1", (F1)=> if List.AnyTrue(List.Transform(Basic,each Text.Contains(F1[Description], _)))=true then F1[Total] else 0 )
in
#"Added Custom"

BNiddrieDavies
Regular Visitor

Hi Artemus,

Thank you for the answer, that has worked and I think the first part of the formula within List.AnyTrue is working because the results are now split into "0"'s..for the "Falses" and errors for the "Trues", the error for the "Trues" is:

"Expression.Error: There is an unknown identifier. Did you use the [field] shorthand for a _[field] outside of an 'each' expression?"

Formula is now written like:
let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Je Header Id", Int64.Type}, {"Description", type text}, {"Total", Int64.Type}}),
#"Added Custom" = Table.AddColumn(#"Changed Type", "Basic Pay1", (F1)=> if List.AnyTrue(List.Transform(Basic,each Text.Contains(F1[Description], _)))=true then [Total] else 0 )
in
#"Added Custom"

Are you able to advise on the error?
Thank you

you would need to use F1[Total] instead of just [Total]

Yaaaaaas!!!
Thank you, that has done it!!!
Hero! Many thanks

artemus
Microsoft Employee
Microsoft Employee

change

each if (F1)=>

to

(F1) => if

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

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! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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