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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
seikenbary
Regular Visitor

How to replace values using column names ?

I am trying to convert the first table to the second table below. my reporting spits out duplicate rows for project for each individual on a project. If you pivot the person column, you can get a single column with each person's name and a 0/1 indicator for whether they are on the project, but i can't figure out the right combination of merging / splitting / unpivoting / pivoting / demoting headers to get to my desired final table. I also can't find the M language syntax to return a single column's name. 

 

I don't care what the fix method is, just want the right output using Power Query and not regular excel formulas. Any ideas? 

 

Table 1

ProjectPerson
AArt
ABart
BTim
CSue
DLarry
DBarry
DGarry

 

Table 2 - desired output

ProjectPeople
AArt, Bart
BTim
CSue
DLarry, Barry, Garry
1 ACCEPTED SOLUTION
Jimmy801
Community Champion
Community Champion

Hello @seikenbary 

 

just use Table.Group with Text.Combine if you want to have in power query. Otherwise use the syntax by @az38 

let
	Source = #table
	(
		{"Project","Person"},
		{
			{"A","Art"},	{"A","Bart"},	{"B","Tim"},	{"C","Sue"},	{"D","Larry"},	{"D","Barry"},	{"D","Garry"}
		}
	),
    Group = Table.Group(Source, {"Project"}, {{"TextCombine", each Text.Combine(_[Person], ", "), type text}})
in
	Group

Copy paste this code to the advanced editor to see how the solution works. If this solution fits your need, copy and past a part of it and implement it in your query, or I could create a custom function what makes it easier to apply if you are not used that much to power query.

If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too

Have fun

Jimmy

View solution in original post

6 REPLIES 6
GokilaRaviraj
Helper II
Helper II

Hi ,

Currently my input table looks like this,

I am fetching current month + remaining months of the year+ next year all the months. This is the logic to fetch months every time.  These months I am fetching it from calendar table and appending here.

 

GokilaRaviraj_2-1727187259925.png

In my original table, i have months till Dec_NFY.

 

Now Estimate q1 value has to be copied to Where ever my table has Jan, Feb, Mar 

Estimate q2 value has be copied to all the columns starts with Apr May jun 

Same logic goes to Q3 and Q4 as well.

 

Sample output.

GokilaRaviraj_3-1727187259927.png

I am trying to write a code something like below,

If column header starts with Sep , for example.

estimate Q3 column value has to be presented in all the columns starts with sep.

 

This code is not working. 

Could anyone pls help me with this ?

 

Thanks in advance.

Jimmy801
Community Champion
Community Champion

Hello @seikenbary 

have you been able to solve the problem with the replies given?

If so, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too

All the best

Jimmy

Jimmy801
Community Champion
Community Champion

Hello @seikenbary 

 

just use Table.Group with Text.Combine if you want to have in power query. Otherwise use the syntax by @az38 

let
	Source = #table
	(
		{"Project","Person"},
		{
			{"A","Art"},	{"A","Bart"},	{"B","Tim"},	{"C","Sue"},	{"D","Larry"},	{"D","Barry"},	{"D","Garry"}
		}
	),
    Group = Table.Group(Source, {"Project"}, {{"TextCombine", each Text.Combine(_[Person], ", "), type text}})
in
	Group

Copy paste this code to the advanced editor to see how the solution works. If this solution fits your need, copy and past a part of it and implement it in your query, or I could create a custom function what makes it easier to apply if you are not used that much to power query.

If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too

Have fun

Jimmy

This is beautiful, THANK YOU! works like a charm.

and double thanks for providing a non-dax solution. i'm aware of what dax is/some features but don't personally use/write it.

az38
Community Champion
Community Champion

Hi @seikenbary 

try this DAX technique.

create a calculated table

Table = 
SUMMARIZE (
    ADDCOLUMNS (
        'Table1';
        "Combined Value"; CONCATENATEX (
            FILTER (
                SUMMARIZE ( 'Table1'; 'Table1'[Project]; [Person] );
                [Project] = EARLIER ( 'Table1'[Project] )
            );
            'Table1'[Person];
            ", "
        )
    );
    [Project];
    [Combined Value]
)

 

do not hesitate to give a kudo to useful posts and mark solutions as solution

LinkedIn


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

many thanks for the quick response. i don't really know yet how to apply DAX but i'm sure this will help others! i got my query working with the combine + group code from the other response. 

Helpful resources

Announcements
Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Top Solution Authors
Top Kudoed Authors