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

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.

Reply
Jabbornon
Regular Visitor

Pivoting a table with custom values?

Hi there, 

 

I am working on a visual in Power BI that looks something like this: 

 

IDValue
1pizza
2hot dogs
2fries
3fries
4burgers
4hot dogs
4pizza
5burgers
5fries
6hot dogs
6burgers
7

pizza

 

The goal my client has is to not only filter the table so that only IDs with more than one value are featured, but to also move the values to go side-by-side like so:

 

IDValue1Value2Value3
2hot dogsfries 
4burgershot dogspizza
5burgersfries 
6hot dogsburgers 

 

I think I would have to do a pivot of some sort to get this to work, but I have no idea how I could assign Value1, Value2, Value3, and so on dynamically in order to make this possible (i.e. make sure it doesn't break with other data variations, if there are more than 3 values for a single ID, and so on). Is this even feasible in Power BI as it is right now?

3 ACCEPTED SOLUTIONS
vicky_
Super User
Super User

It's doable without any pivots:

Ids with More Than One Value = IF(
    COUNTROWS(VALUES('Table'[Value])) > 1 && HASONEVALUE('Table'[ID]), //i.e more than one value per id and is not the total row
    CONCATENATEX('Table', 'Table'[Value], ", ")
)

vicky__0-1713911805106.png

 

View solution in original post

Anonymous
Not applicable

Hi @vicky_ ,thanks for the quick reply, I'll add further.

Hi @Jabbornon ,

The Table data is shown below:

vzhouwenmsft_0-1714033813189.png

Please follow these steps:

1.Use the following DAX expression to create a table

Table 2 = SUMMARIZE('Table','Table'[ID],"Col",CONCATENATEX('Table',[Value],","))

vzhouwenmsft_1-1714033884483.png

2.Copying table data to Excel

vzhouwenmsft_2-1714033952519.png

3.Use Power BI Desktop to connect to the Excel file where the data is stored and open Power Query.

vzhouwenmsft_3-1714034052177.png

4.split column

vzhouwenmsft_4-1714034149386.png

5.Final output

vzhouwenmsft_5-1714034176440.png

Split columns by delimiter - Power Query | Microsoft Learn

 

Best Regards,
Wenbin Zhou
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

View solution in original post

Ashish_Mathur
Super User
Super User

Hi,

This M code works

let
    Source = Excel.CurrentWorkbook(){[Name="Data"]}[Content],
    #"Grouped Rows" = Table.Group(Source, {"ID"}, {{"All", each Table.AddIndexColumn(_,"Index",1,1)}, {"Count", each Table.RowCount(_), Int64.Type}}),
    #"Filtered Rows" = Table.SelectRows(#"Grouped Rows", each [Count] > 1),
    #"Expanded All" = Table.ExpandTableColumn(#"Filtered Rows", "All", {"Value", "Index"}, {"Value", "Index"}),
    #"Removed Columns" = Table.RemoveColumns(#"Expanded All",{"Count"}),
    #"Added Prefix" = Table.TransformColumns(#"Removed Columns", {{"Index", each "Value " & Text.From(_, "en-IN"), type text}}),
    #"Pivoted Column" = Table.Pivot(#"Added Prefix", List.Distinct(#"Added Prefix"[Index]), "Index", "Value")
in
    #"Pivoted Column"

Hope this helps.

Ashish_Mathur_0-1714089141302.png

 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

5 REPLIES 5
Ashish_Mathur
Super User
Super User

Hi,

This M code works

let
    Source = Excel.CurrentWorkbook(){[Name="Data"]}[Content],
    #"Grouped Rows" = Table.Group(Source, {"ID"}, {{"All", each Table.AddIndexColumn(_,"Index",1,1)}, {"Count", each Table.RowCount(_), Int64.Type}}),
    #"Filtered Rows" = Table.SelectRows(#"Grouped Rows", each [Count] > 1),
    #"Expanded All" = Table.ExpandTableColumn(#"Filtered Rows", "All", {"Value", "Index"}, {"Value", "Index"}),
    #"Removed Columns" = Table.RemoveColumns(#"Expanded All",{"Count"}),
    #"Added Prefix" = Table.TransformColumns(#"Removed Columns", {{"Index", each "Value " & Text.From(_, "en-IN"), type text}}),
    #"Pivoted Column" = Table.Pivot(#"Added Prefix", List.Distinct(#"Added Prefix"[Index]), "Index", "Value")
in
    #"Pivoted Column"

Hope this helps.

Ashish_Mathur_0-1714089141302.png

 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

Hi @vicky_ ,thanks for the quick reply, I'll add further.

Hi @Jabbornon ,

The Table data is shown below:

vzhouwenmsft_0-1714033813189.png

Please follow these steps:

1.Use the following DAX expression to create a table

Table 2 = SUMMARIZE('Table','Table'[ID],"Col",CONCATENATEX('Table',[Value],","))

vzhouwenmsft_1-1714033884483.png

2.Copying table data to Excel

vzhouwenmsft_2-1714033952519.png

3.Use Power BI Desktop to connect to the Excel file where the data is stored and open Power Query.

vzhouwenmsft_3-1714034052177.png

4.split column

vzhouwenmsft_4-1714034149386.png

5.Final output

vzhouwenmsft_5-1714034176440.png

Split columns by delimiter - Power Query | Microsoft Learn

 

Best Regards,
Wenbin Zhou
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

vicky_
Super User
Super User

It's doable without any pivots:

Ids with More Than One Value = IF(
    COUNTROWS(VALUES('Table'[Value])) > 1 && HASONEVALUE('Table'[ID]), //i.e more than one value per id and is not the total row
    CONCATENATEX('Table', 'Table'[Value], ", ")
)

vicky__0-1713911805106.png

 

I have done that in a prior project, but I was wondering specifically if it is possible to separate them into different columns instead of concatenating them into one single column. 

If you need a dynamic amount of columns, then no I can't think of a way to get it to show.
If you only have a set number of columns (i.e 3), then you can use TOPN or INDEX in 3 different measures to grab the 1st, 2nd, 3rd value (sorted alphabetically or something). The only downside to this being that there will be blank values / columns and it is tedious to set up and to maintain so I would not recommend.

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors