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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
VAMONIE
New Member

power query

Hi.

I have some data and like to have it all on the same row. This is my example.

VAMONIE_0-1743076650884.png

When I pivot on Artikel I get this. But I want to have all units in the same row and a sum of column Amount.

VAMONIE_1-1743076692315.png

This Is what I want but cant get it right. Can anybody try to explaing how to do för a beginner in Power Query, Thanks.

VAMONIE_2-1743076845036.png

 

4 ACCEPTED SOLUTIONS
Cookistador
Super User
Super User

Hello @VAMONIE 

 

It is an interesting case, I made a test which is working, maybe there is an elegant way to achieve that, but I will follow this post to see that

First I would copy your table in Power query and make a group by

Cookistador_0-1743078792942.png

 

Now in your first table

 you have to pivot your artikel column

Cookistador_1-1743078898820.png

To ge the following table

Cookistador_2-1743078922467.png

 

 

Then, you have to make a merge between your 2 tables

Cookistador_3-1743078953367.png

 

 

Your expand the total from the other table and you can delete the amount from your source table

and I should get the results you need

There is maybe a most efficient way, so I would interested to see it 🙂

View solution in original post

dufoq3
Super User
Super User

Hi @VAMONIE, check this:

 

Output

dufoq3_0-1743093266545.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMtIzNNAzMjAyVdJRCkgtKs7PU3AEMn0Ob8sDUpZAbGpgoBSrg1OlU35eaTFUqaEBfrWuFSVFiUDaDIiNcSt1ItoBTiQ4wIk0BwQXpCZnJuZAFZuYwhUbEh1c2FTici02tThci64Ud3BhU0msA/AEFzalWIIrFgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Datum = _t, Name = _t, Artikel = _t, Units = _t, Amount = _t]),
    ChangedType = Table.TransformColumnTypes(Source,{{"Units", type number}, {"Amount", type number}, {"Datum", type date}}, "sk-SK"),
    GroupedRows = Table.Group(ChangedType, {"Datum", "Name"}, {{"T", each 
        [ a = Table.RemoveColumns(_, {"Amount"}),
          b = Table.Pivot(a, List.Distinct(a[Artikel]), "Artikel", "Units"),
          c = Table.AddColumn(b, "Amount", (x)=> List.Sum([Amount]), type number)
        ][c], type table}}),
    ComibnedT = Table.Combine(GroupedRows[T])
in
    ComibnedT

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

slorin
Super User
Super User

Hi @VAMONIE 

Another possibility

let
Source = Your_Source,
Artikel = List.Distinct(Source[Artikel]),
Group = Table.Group(Source, {"Datum", "Name"},
{{"Data", each Table.FromRows({[Units]}, [Artikel])},
{"Amount", each List.Sum([Amount]), type nullable number}}),
Expand = Table.ExpandTableColumn(Group, "Data", Artikel, Artikel)
in
Expand

Stéphane

View solution in original post

SundarRaj
Super User
Super User

Hi @VAMONIE , another way to look at it. I'll attach the images of the output and M code used to achieve this. Thanks!

SundarRaj_0-1743145258423.png

SundarRaj_1-1743145340516.png

 

 

Sundar Rajagopalan

View solution in original post

10 REPLIES 10
VAMONIE
New Member

Worked fine, Thanks 

V-yubandi-msft
Community Support
Community Support

Hi @VAMONIE ,

Has your issue been resolved, or do you require any further information? Your feedback is valuable to us. If the solution was effective, please mark it as 'Accepted Solution' to assist other community members experiencing the same issue.

V-yubandi-msft
Community Support
Community Support

Hi @VAMONIE ,

May I ask if you have resolved this issue? If so, please mark the helpful reply and accept it as the solution. This will be helpful for other community members who have similar problems to solve it faster.

Thank you.

V-yubandi-msft
Community Support
Community Support

Hi @VAMONIE ,

We noticed we haven't received a response from you yet, so we wanted to follow up and ensure the solution we provided addressed your issue. If you require any further assistance or have additional questions, please let us know.

Your feedback is valuable to us, and we look forward to hearing from you soon.

 

Thanks..

V-yubandi-msft
Community Support
Community Support

Hi @VAMONIE ,

@dufoq3  has provided an accurate solution to your issue. Could you please confirm if it meets your requirements? If you need any further clarification.

If your issue is resolved, kindly mark it as the Accepted Solution. Otherwise, let us know how we can assist you further.

Thank you all for your valuable feedback.

 

Regards,

Yugandhar.

SundarRaj
Super User
Super User

Hi @VAMONIE , another way to look at it. I'll attach the images of the output and M code used to achieve this. Thanks!

SundarRaj_0-1743145258423.png

SundarRaj_1-1743145340516.png

 

 

Sundar Rajagopalan
slorin
Super User
Super User

Hi @VAMONIE 

Another possibility

let
Source = Your_Source,
Artikel = List.Distinct(Source[Artikel]),
Group = Table.Group(Source, {"Datum", "Name"},
{{"Data", each Table.FromRows({[Units]}, [Artikel])},
{"Amount", each List.Sum([Amount]), type nullable number}}),
Expand = Table.ExpandTableColumn(Group, "Data", Artikel, Artikel)
in
Expand

Stéphane

dufoq3
Super User
Super User

Hi @VAMONIE, check this:

 

Output

dufoq3_0-1743093266545.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMtIzNNAzMjAyVdJRCkgtKs7PU3AEMn0Ob8sDUpZAbGpgoBSrg1OlU35eaTFUqaEBfrWuFSVFiUDaDIiNcSt1ItoBTiQ4wIk0BwQXpCZnJuZAFZuYwhUbEh1c2FTici02tThci64Ud3BhU0msA/AEFzalWIIrFgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Datum = _t, Name = _t, Artikel = _t, Units = _t, Amount = _t]),
    ChangedType = Table.TransformColumnTypes(Source,{{"Units", type number}, {"Amount", type number}, {"Datum", type date}}, "sk-SK"),
    GroupedRows = Table.Group(ChangedType, {"Datum", "Name"}, {{"T", each 
        [ a = Table.RemoveColumns(_, {"Amount"}),
          b = Table.Pivot(a, List.Distinct(a[Artikel]), "Artikel", "Units"),
          c = Table.AddColumn(b, "Amount", (x)=> List.Sum([Amount]), type number)
        ][c], type table}}),
    ComibnedT = Table.Combine(GroupedRows[T])
in
    ComibnedT

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

lbendlin
Super User
Super User

Please don't do that in Power Query. Your original data is in perfect shape.  let the Matrix visual in Power BI do the work for you.

Cookistador
Super User
Super User

Hello @VAMONIE 

 

It is an interesting case, I made a test which is working, maybe there is an elegant way to achieve that, but I will follow this post to see that

First I would copy your table in Power query and make a group by

Cookistador_0-1743078792942.png

 

Now in your first table

 you have to pivot your artikel column

Cookistador_1-1743078898820.png

To ge the following table

Cookistador_2-1743078922467.png

 

 

Then, you have to make a merge between your 2 tables

Cookistador_3-1743078953367.png

 

 

Your expand the total from the other table and you can delete the amount from your source table

and I should get the results you need

There is maybe a most efficient way, so I would interested to see it 🙂

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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