Microsoft Fabric Community Conference 2025, March 31 - April 2, Las Vegas, Nevada. Use code FABINSIDER for a $400 discount.
Register nowGet inspired! Check out the entries from the Power BI DataViz World Championships preliminary rounds and give kudos to your favorites. View the vizzies.
Hi!
I have a column with numbers with either 4 or 7 characters, how can I divide the column into the ones with 4 and the ones with 7?
Solved! Go to Solution.
Please provide sample data and expected outcome from that data.
There are many ways to accomplish this and variations depend on the nature of your data and expected outcome.
For example, if your data looks like:
This code
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQyNlGK1YEwTM3MwWwQE84wM7cAs0FMOMPcwlIpNhYA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Column", Int64.Type}}),
Split = Table.FromColumns(
{Table.SelectRows(#"Changed Type", each Text.Length(Text.From([Column]))=4)[Column],
Table.SelectRows(#"Changed Type", each Text.Length(Text.From([Column]))=7)[Column]},
type table[Four=Int64.Type,Seven=Int64.Type])
in
#"Split"
would produce:
Hi @Tomasavlis , here's a quick way to solve this problem. Do have a look. I'm attaching two images, one for output and second for the M code. Thanks!
Please provide sample data and expected outcome from that data.
There are many ways to accomplish this and variations depend on the nature of your data and expected outcome.
For example, if your data looks like:
This code
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQyNlGK1YEwTM3MwWwQE84wM7cAs0FMOMPcwlIpNhYA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Column", Int64.Type}}),
Split = Table.FromColumns(
{Table.SelectRows(#"Changed Type", each Text.Length(Text.From([Column]))=4)[Column],
Table.SelectRows(#"Changed Type", each Text.Length(Text.From([Column]))=7)[Column]},
type table[Four=Int64.Type,Seven=Int64.Type])
in
#"Split"
would produce:
Something like this, column with random numbers with no rule, just there are some with 7 and others with 4 digits. Although in the picture it's in between, in the real data set it's random
Seems like my answer below does what you are looking for.
Yes it does, thank you so much!
You would need to research the Power Query exact logic functions to use, but you could go off the length of the string. Create two calculated columns:
Column Four digits = IF Length of original column = 4 then original column, else null.
Proud to be a Super User! | |
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Check out the February 2025 Power BI update to learn about new features.
User | Count |
---|---|
30 | |
26 | |
24 | |
13 | |
10 |
User | Count |
---|---|
24 | |
23 | |
18 | |
12 | |
9 |