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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric 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
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

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

Top Solution Authors