Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Combine rows with similar information into 1

I have a table that looks like this example:

Order      Bagged        Shipped
----------------------------------
1             Y    
2                           Y
1                           Y
3             Y

I want to combine like order numbers into 1 row like below:

Order      Bagged        Shipped
----------------------------------
1             Y             Y
2                           Y
3             Y

How can I do this in PowerBi desktop?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Assuming your data really is as simple as your example (values are either null or ‘Y’ and no conflicts), I suggest something like:

SELECT Order, MAX(Bagged), MAX(Shipped)
FROM mytable
GROUP BY Order

The GROUP BY Order indicates you want one row per order, the MAX for the other columns ensures you get the ‘Y’ (if it exists for that Order) or null (if ‘Y’ doesn’t exist for that Order).

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading