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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Anonymous
Not applicable

Splitting columns based on data from another column

Hi all, 

 

I have data that looks something like this:

ProductNumber
A1
A2
A3
A4
B1
B2
B3

 

How do I manipulate or split the columns so it looks something like this where each product is given a new column for its number:

ProductNumberNumber (2)
A1 
A2 
A3 
A4 
B 1
B 2
B 3

 

Any help would be fully appreciated. Thank you.

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@Anonymous , Create two new columns like

Number 1= if([Product]= "A", [Number], blank())
Number 2= if([Product]= "B", [Number], blank())

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

5 REPLIES 5
DavisBI
Solution Specialist
Solution Specialist

Hi, @Anonymous ,

 

You can declare a function in the powerquery editor. The product number can be used as a parameter, and then the new column will be renamed every time the parameter is passed. In this way, when the function is called, due to the different column names, new columns can be added automatically.

 

I can do a demo if you're not clear about that.

 

Best.

Anonymous
Not applicable

Hi sorry but I am new to Power BI. Mind doing a demo if you are willing to? Thank you very much

amitchandak
Super User
Super User

@Anonymous , Create two new columns like

Number 1= if([Product]= "A", [Number], blank())
Number 2= if([Product]= "B", [Number], blank())

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

Hi when I tried this, it says that I have a 'Token RightParen expected' error. Any way to fix this?

DavisBI
Solution Specialist
Solution Specialist

@Anonymous 

Suppose you have the following data:

 

 

 

let
DATA = 
    Table.FromRecords(
        {
            [ID = "A", Number = 12],
            [ID = "A", Number = 5],
            [ID = "A", Number = 6],
            [ID = "A", Number = 8],
            [ID = "B", Number = 14],
            [ID = "B", Number = 9],
            [ID = "B", Number = 7],
            [ID = "B", Number = 7],
            [ID = "C", Number = 5],
            [ID = "C", Number = 16],
            [ID = "C", Number = 18]
        },
        type table [ID = nullable text, Number = nullable number]
    )
in
    DATA

 

 

 

And then you can create a new function using M code:

 

 

 

(ID_Code as text) => 
let
DATA = 
    DATA,
    DATA_Filtered = Table.SelectRows(DATA, each ([ID] = ID_Code)),
    DATA_Renamed = Table.RenameColumns(DATA_Filtered,{{"Number", ID_Code}})

in
    DATA_Renamed

 

 

 

Since that, you need to create a list that including all distinct values of [ID] so that PowerQuery can run the function for each [ID] after you click "Invoke Custom Function" and you'll get what you want in the end. This is a full dynamic solution.

 

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.