Logical Data Type Custom Column in Power Query

Bob_W

New Member
Joined
Jun 15, 2017
Messages
9
I have created a custom column, which generates a 1 or 0 for each field based on a simple if statement, that I've defined as a Logical Data type.

My issue is that when applied and viewed in Power BI as a Data table the column is entirely empty and generates a data type error. However, if I simply change the data type to "Int64.Type" then it works fine.

Hopefully someone can tell me where this is going wrong please?

Power Query:
#"Mrg: dim_cust_inter_cmpny" = Table.NestedJoin(#"Table1", {"CustName"}, dim_cust_inter_cmpny, {"Customer"}, "dim_cust_inter_cmpny", JoinKind.LeftOuter),
        #"Expd: dim_cust_inter_cmpny" = Table.ExpandTableColumn(#"Mrg: dim_cust_inter_cmpny", "dim_cust_inter_cmpny", {"Inter Company"}, {"dim_cust_inter_cmpny.Inter Company"}),
#"Cus_Col: Inter_Co" = Table.AddColumn(#"Expd: dim_cust_inter_cmpny", "Inter_Co",
        each if [dim_cust_inter_cmpny.Inter Company] = "Y" then 1
        else 0, Logical.Type)
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Logical type is for true or false, excel will interpret 1 and 0 as true or false and vice versa, but in PQ it looks like you need to use true and false rather than 1 and 0 for logical type. Also syntax I think should be type logical not Logical.Type

#"Cus_Col: Inter_Co" = Table.AddColumn(#"Expd: dim_cust_inter_cmpny", "Inter_Co",
each if [dim_cust_inter_cmpny.Inter Company] = "Y" then true
else false, type logical)
 
Upvote 0
Solution
#"Cus_Col: Inter_Co" = Table.AddColumn(#"Expd: dim_cust_inter_cmpny", "Inter_Co",
each if [dim_cust_inter_cmpny.Inter Company] = "Y" then true
else false, type logical)
Thanks for the reply.

You are right that I need to specify the true/false rather than using 1/0 (thought I had read that was ok in PQ, but apparently not! :whistle: )

The data type though is "Logical.Type" in the 2020 version of PBI I've got. I was picking it up from the Intelli-sense prompts. Not used earlier versions so maybe that syntax has been changed?
 
Upvote 0
Thanks for the feedback. I agree, it seems to be a version thing. In my version (PQ in Excel 2019) type logical works and Logical.Type returns an error.
 
Upvote 0

Forum statistics

Threads
1,215,352
Messages
6,124,449
Members
449,160
Latest member
nikijon

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top