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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
Anonymous
Not applicable

Create 3 rows for every record

i have recods in excel like

 

company region market        rev1India revgermany   revsingapore

EAC Sols  APAC   Germany    44682       -                   12455

 

Now i want in power bi to look like

Company  Region  Market       Country        Rev

EAC sols    APAC    Germany    India             44682

EAC sols    APAC    Germany    Germany        -

EAC sols    APAC    Germaby    Singapore     12455

 

So basically i need 2 things

create rows 3 rows for every record for india,germany and singapore and then put the revenue values against it,

 

Help!! 

 

2 ACCEPTED SOLUTIONS
MFelix
Super User
Super User

Hi @Anonymous ,

 

On the query editor select the 3 columns of Rev and then choose unpivot. You will then get 2 column attribute and value.

 

You then just have to rename the columns and on the attribute column make a replace rev by nothing and you you get the information needed.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcnV0VgjOzylW0lFyDHB0BlLuqUW5iXmVQJaJiZmFEZA2AGJDIxNTU6XYWAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Company = _t, Region = _t, Market = _t, revIndia = _t, Revgermany = _t, revsingapore = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Company", type text}, {"Region", type text}, {"Market", type text}, {"revIndia", Int64.Type}, {"Revgermany", Int64.Type}, {"revsingapore", Int64.Type}}),
    #"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Company", "Region", "Market"}, "Attribute", "Value"),
    #"Renamed Columns" = Table.RenameColumns(#"Unpivoted Columns",{{"Attribute", "Country"}}),
    #"Replaced Value" = Table.ReplaceValue(#"Renamed Columns","rev","",Replacer.ReplaceText,{"Country"})
in
    #"Replaced Value"

Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



View solution in original post

v-xuding-msft
Community Support
Community Support

Hi @Anonymous ,

 

If you want to implement it with DAX, you could try this:

 

Create a new table:

Table 1 =
UNION (
    SELECTCOLUMNS (
        'Table',
        "Company", 'Table'[Company],
        "Region", 'Table'[Region],
        "Market", 'Table'[Market],
        "Country", "India",
        "Rev", 'Table'[revIndia]
    ),
    SELECTCOLUMNS (
        'Table',
        "Company", 'Table'[Company],
        "Region", 'Table'[Region],
        "Market", 'Table'[Market],
        "Country", "Germany",
        "Rev", 'Table'[Revgermany]
    ),
    SELECTCOLUMNS (
        'Table',
        "Company", 'Table'[Company],
        "Region", 'Table'[Region],
        "Market", 'Table'[Market],
        "Country", "Singapore",
        "Rev", 'Table'[revsingapore]
    )
)

 

v-xuding-msft_0-1599037185839.png

 

 

Best Regards,
Xue Ding
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
v-xuding-msft
Community Support
Community Support

Hi @Anonymous ,

 

If you want to implement it with DAX, you could try this:

 

Create a new table:

Table 1 =
UNION (
    SELECTCOLUMNS (
        'Table',
        "Company", 'Table'[Company],
        "Region", 'Table'[Region],
        "Market", 'Table'[Market],
        "Country", "India",
        "Rev", 'Table'[revIndia]
    ),
    SELECTCOLUMNS (
        'Table',
        "Company", 'Table'[Company],
        "Region", 'Table'[Region],
        "Market", 'Table'[Market],
        "Country", "Germany",
        "Rev", 'Table'[Revgermany]
    ),
    SELECTCOLUMNS (
        'Table',
        "Company", 'Table'[Company],
        "Region", 'Table'[Region],
        "Market", 'Table'[Market],
        "Country", "Singapore",
        "Rev", 'Table'[revsingapore]
    )
)

 

v-xuding-msft_0-1599037185839.png

 

 

Best Regards,
Xue Ding
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
amitchandak
Super User
Super User

MFelix
Super User
Super User

Hi @Anonymous ,

 

On the query editor select the 3 columns of Rev and then choose unpivot. You will then get 2 column attribute and value.

 

You then just have to rename the columns and on the attribute column make a replace rev by nothing and you you get the information needed.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcnV0VgjOzylW0lFyDHB0BlLuqUW5iXmVQJaJiZmFEZA2AGJDIxNTU6XYWAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Company = _t, Region = _t, Market = _t, revIndia = _t, Revgermany = _t, revsingapore = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Company", type text}, {"Region", type text}, {"Market", type text}, {"revIndia", Int64.Type}, {"Revgermany", Int64.Type}, {"revsingapore", Int64.Type}}),
    #"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Company", "Region", "Market"}, "Attribute", "Value"),
    #"Renamed Columns" = Table.RenameColumns(#"Unpivoted Columns",{{"Attribute", "Country"}}),
    #"Replaced Value" = Table.ReplaceValue(#"Renamed Columns","rev","",Replacer.ReplaceText,{"Country"})
in
    #"Replaced Value"

Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Greg_Deckler
Super User
Super User

@Anonymous - Select your last three columns in Power Query editor and then right-click in the column header area and select Unpivot.

 

 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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