Power Query Editor, how to create parse mixed data column to custom column

WillWullems

New Member
Joined
May 27, 2017
Messages
2
Hi all,

I am new to Power Query, and I am having some issues in processing a text file.
There is a column that contains both numbers and text.
All numbers in this column are customers numbers.
All records belong to the same customer (until a record starts with a different customer number)

I would like to create a custom column for all records.
In "normal" excel, I would just use an if, combined with isnumber.

I tried using the conditional column, but I am a bit puzzled on how to set the criteria.

Thanks in advance.
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
You can use Value.Type and Type.Is to check for types, e.g.:

Code:
= if Type.Is(Value.Type([Value]), type text) then "Text" else if Type.Is(Value.Type([Value]), type number) then "Number" else "Neither text nor number"
 
Upvote 0
Thanks for your reply.

When reading my question, I understand I was a bit unclear.
I see how the calculated column takes the value when available.
When the mixed data is text, I would like to repeat the number from the previous record (rather then "Text").
 
Upvote 0
Edit: this is still a reaction to the original question.

Even shorter: you can use Value.Is:

Code:
= if Value.Is([Value], type text) then "Text" else if Value.Is([Value], type number) then "Number" else "Neither text nor number"
 
Last edited:
Upvote 0
As a reaction to the updated question, this will work:

Code:
let
    Source = Table1,
    #"Added Custom" = Table.AddColumn(Source, "Custom column", each if Value.Is([Value], type number) then [Value] else null),
    #"Filled Down" = Table.FillDown(#"Added Custom",{"Custom column"})
in
    #"Filled Down"

By the way: "Calculated Column" suggests a DAX solution rather than my Power Query solution with a "custom column".
Just to avoid misunderstandings.
 
Upvote 0
Hi Marcel,
We can directly use "is" operator in the query (will be shorter) ;)
Code:
let
     Source = Table1,
    #"Added Custom" = Table.AddColumn(Source, "Custom column", each if [Value] is number then [Value] else null),
    #"Filled Down" = Table.FillDown(#"Added Custom",{"Custom column"})
in
    #"Filled Down"
Regards :)
 
Last edited:
Upvote 0
Hi Bill,

Sure, thanks! I have been busy documenting comparer functions lately (and parameters "comparer", "equationCriteria" and "comparisonCriteria"), so I completely overlooked the obvious "is".
Well, at least that makes this a high educational topic, with the alternatives presented.

Cheers!
 
Upvote 0

Forum statistics

Threads
1,214,982
Messages
6,122,581
Members
449,089
Latest member
Motoracer88

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