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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
paolomint
Helper III
Helper III

Partial pivoting

Dear all,

 

how Can i trasform my table:

 

COMPANYSHOPYEARCODVALUE
PaoloROME2020FT100
PaoloROME2020FT450
PaoloROME2020CO200
ValeriaVENICE2020FT80
ValeriaVENICE2020SE20

 

in the following way in Power query?

 

COMPANYSHOPYEARFTCOSE
PaoloROME2020100  
PaoloROME2020450200 
PaoloROME2020   
ValeriaVENICE202080  
ValeriaVENICE2020  20

 

thanks in advance

Paolo

7 REPLIES 7
paolomint
Helper III
Helper III

Hi  @edhans 

here you can find the real data I'm working on in the first sheet (database), in the other sheet (result) you can see what I'd like to obtain 

https://www.dropbox.com/s/z0dry0z35pxk9vb/example_pbi.xlsx?dl=0

 

Here you are an extract 

            

DITTA

CENTRO                                 

YEAR 

COD VOCE

IMPORTO

COMALI

P001 EUROSPIN - ISOLA 1

2020

CEN-ON

6,01

COMALI

P001 EUROSPIN - ISOLA 1

2020

CEN-ON

72,2

COMALI

P001 EUROSPIN - ISOLA 1

2020

CEN-ON

535,07

COMALI

P001 EUROSPIN - ISOLA 1

2020

CEN-ONE

70

COMALI

P001 EUROSPIN - ISOLA 1

2020

CEN-ONE

120

COMALI

P001 EUROSPIN - ISOLA 1

2020

CEN-ONE

480

COMALI

P001 EUROSPIN - ISOLA 1

2020

CEN-ONE

650,18

COMALI

P001 EUROSPIN - ISOLA 1

2020

CEN-ONE

1612

COMALI

P001 EUROSPIN - ISOLA 1

2020

CEN-ONE

3919,59

COMALI

P001 EUROSPIN - ISOLA 1

2020

CENT-ACOS

8860,16

COMALI

P001 EUROSPIN - ISOLA 1

2020

CENT-ACOS

52646

COMALI

P001 EUROSPIN - ISOLA 1

2020

CENT-ACOS

110937,72

COMALI

P001 EUROSPIN - ISOLA 1

2020

CENT-MAN

620,43

COMALI

P001 EUROSPIN - ISOLA 1

2020

CENT-MAN

2007,94

COMALI

P001 EUROSPIN - ISOLA 1

2020

CENT-MAN

2948

COMALI

P001 EUROSPIN - ISOLA 1

2020

CENT-MAN

5085

COMALI

P001 EUROSPIN - ISOLA 1

2020

CENT-MAN

15120,75

COMALI

P001 EUROSPIN - ISOLA 1

2020

CENT-MAN

76652,95

 

Why I'm trying to do that?

 I need to do some calculation like the following:

EBITDA = (CEN-ON) - (CEN-ONE) 

EBIT = (EBITDA) - (CENT-ACOS)

RESD = (EBIT) - (CENT-MAN)

Then I need to visualize that in this form (as matrix):

 

DITTA

CENTRO

YEAR

COD VOCE

IMPORTO

COMALI 

P001 EUROSPIN - ISOLA 1

2020

CEN-ON

400

COMALI

P001 EUROSPIN - ISOLA 1

2020

CEN-ONE

150

COMALI

P001 EUROSPIN - ISOLA 1

2020

EBITDA

250

COMALI

P001 EUROSPIN - ISOLA 1

2020

CENT-ACOS

20

COMALI

P001 EUROSPIN - ISOLA 1

2020

EBIT

230

COMALI

P001 EUROSPIN - ISOLA 1

2020

CENT-MAN

100

COMALI

P001 EUROSPIN - ISOLA 1

2020

RESD

130

 

I know that I can use directly dax formula instead of create a new table but I'm not expert in dax and using a table is easier for me. Anyhow I hope you can help me to find the best way to do that.

 

I hope everything is clear, if not please ask and I will reply timely

thank you very much

Paolo

 

Hi @edhans 

sorry to bother you,

did you have a look to the data?

Everthing is clear?

Thank you very much

Paolo

CNENFRNL
Community Champion
Community Champion

@paolomint , easy enough

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCkjMz8lX0lEK8vd1BVJGBkYGQMotBEgYGhgoxergVWJiik+Jsz+YDVESlpiTWpSZCBQJc/XzdEY3yYKQqmAIWyk2FgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [COMPANY = _t, SHOP = _t, YEAR = _t, COD = _t, VALUE = _t]),
    #"Added Index" = Table.AddIndexColumn(Source, "Index"),
    #"Pivoted Column" = Table.Pivot(#"Added Index", List.Distinct(#"Added Index"[COD]), "COD", "VALUE"),
    #"Removed Columns" = Table.RemoveColumns(#"Pivoted Column",{"Index"})
in
    #"Removed Columns"

Screenshot 2021-04-06 180133.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

Great @CNENFRNL , thank you very much

In the easy table I usued as example, It works.

 

When I try to apply it on my real model, I obtain the following error message:

 

It is not possible to convert null value on text type:

Detail

Type=[Type]

 

May I add another line to avoid this error?

thank you very much

@paolomint - PIVOT has limits. I think this is why it isn't on the right-click menu. It can be finnicky. That said, three questions:

  1. Why is your value text? Shouln't that be a whole number, not text?
  2. Why not aggregate the values? So the table below is the result?
  3. Why are you pivoting in the first place? It depends on the data set, but it could be advantageous in DAX to keep these as they are.

edhans_0-1617748229314.png

 



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

thank you @edhans 

1. the message error gets out when I try to apply the procedure in my real model

2. yes, I can aggregate 

3. About dax, It would be great but I don't know how to do. Can you kindly help me?

thanks in advance

 

Paolo

Provide some good data for us to assist with @paolomint as well as expected results. Show us where you want to end up, rather than asking how to do a specific thing. That thing (pivoting) may not be a good way to get to your destination.

 

How to get good help fast. Help us help you.

How To Ask A Technical Question If you Really Want An Answer

How to Get Your Question Answered Quickly - Give us a good and concise explanation
How to provide sample data in the Power BI Forum - Provide data in a table format per the link, or share an Excel/CSV file via OneDrive, Dropbox, etc.. Provide expected output using a screenshot of Excel or other image. Do not provide a screenshot of the source data. I cannot paste an image into Power BI tables.



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.