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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
sidtembe
New Member

Need Help regarding Power Query

I am new to PowerQuery and not a technical person. However, I am using PowerBI for some analysis. I have loaded data in tables and used basic joins to merge and get the final dataset. Everything works fine so far. Now, in the final dataset, I have an identifier ex - Unique ID and then there is a column which has values such as - School or Office. So, there may be either one or two rows for a unique ID as below:

Unique ID        Location

---------------------------

1111                 Office

2222                 School

3333                 Office

3333                 School

Now, I want to have a new column (Say 'Type) which reads the unique ID columns and assigns values such as - Office, or School , or Both (if it has two rows). So, in above table ID - 1111 will be Office, 2222 will be School, and 3333 will be Both

1 ACCEPTED SOLUTION
dufoq3
Super User
Super User

Hi @sidtembe,

 

Result

dufoq3_0-1715016121338.png

let
    Source = #table(type table[Unique ID=Int64.Type, Location=text], {{1111, "Office"}, {2222, "School"}, {3333, "Office"}, {3333, "School"}}),
    GroupedRows = Table.Group(Source, {"Unique ID"}, {{"All", each Table.AddColumn(_, "Type", (x)=> if List.Count(List.Distinct([Location])) > 1 then "Both" else x[Location], type text), type table}}),
    CombinedAll = Table.Combine(GroupedRows[All])
in
    CombinedAll

Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

View solution in original post

1 REPLY 1
dufoq3
Super User
Super User

Hi @sidtembe,

 

Result

dufoq3_0-1715016121338.png

let
    Source = #table(type table[Unique ID=Int64.Type, Location=text], {{1111, "Office"}, {2222, "School"}, {3333, "Office"}, {3333, "School"}}),
    GroupedRows = Table.Group(Source, {"Unique ID"}, {{"All", each Table.AddColumn(_, "Type", (x)=> if List.Count(List.Distinct([Location])) > 1 then "Both" else x[Location], type text), type table}}),
    CombinedAll = Table.Combine(GroupedRows[All])
in
    CombinedAll

Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors
Top Kudoed Authors