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

How to refer to the column name in an IF formula in PQ

Hallo all,

 

I need to refer to and then use the column name in an IF statement.

 

For example, in a new column, called Category, I want to say:

 

if any of columns start with 100. and the value within the columns also begins with 100. then "Sales Cat A" else if any of the columns start with 200. and the value within the columns also begins with 200. then "Sales Cat B" else if....

 

Nigel_Mayhew_0-1635481990210.png

 

I know how to construct the IF statement itself, but I need help please with referring to the columns names/headers within the formula.

 

Is this possible?

 

Cheers.  

1 ACCEPTED SOLUTION
wdx223_Daniel
Super User
Super User

NewStep=Table.AddColumn(PreviousStepName,"Category",each List.Skip({{"100.","Sales Cat A"},{"200.","Sales Cat B"},{"300.","Sales Cat C"}},(x)=>Table.IsEmpty(Table.SelectRows(Record.ToTable(_),each Text.StartsWith([Name],x{0}) and Text.StartsWith([Value],x{0})))){0}?{1}? ??"Other Cat")

View solution in original post

2 REPLIES 2
wdx223_Daniel
Super User
Super User

NewStep=Table.AddColumn(PreviousStepName,"Category",each List.Skip({{"100.","Sales Cat A"},{"200.","Sales Cat B"},{"300.","Sales Cat C"}},(x)=>Table.IsEmpty(Table.SelectRows(Record.ToTable(_),each Text.StartsWith([Name],x{0}) and Text.StartsWith([Value],x{0})))){0}?{1}? ??"Other Cat")

Anonymous
Not applicable

Absolute magic...worked perfectly....thanks Daniel!

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