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
MRHUP
Frequent Visitor

Copying Content of a Matrix to Excel

Hi,

I would like to periodically transfer the data of some visuals (matrixes) from Power BI to Excel. For this I am using the export function to CSV. Here I run into the issue that the entire layout is shaken up when loading this CSV into Excel. Now I have solved this for several matrixes by editing with M code in Excel, but the table below is for me next level...

 

The PBI matrix below is concerned:

1 - PBI.png

Using the M code (without any other adjustments), the import into Excel leads to:

5 - Imported in Excel.png

When loading the export CSV into Excel manually invoking the delimiter option, the following comes up:

4 - Imported in Excel.png

I have uploaded this CSV file to https://file.io/y27QsPYvaIRu.

 

However, I would like to see this again as follows in Excel (the name Group upper left is not necessary):

3- Goal.png

Does anyone have any idea how to get this done with M code?

 

Thanks in advance for thinking along!

1 ACCEPTED SOLUTION

Hi @MRHUP ,

 

Please follow the steps below.
1. Remove the row where "Group" is located.

vkkfmsft_0-1653468810401.png

vkkfmsft_1-1653468828987.png

 

2. Select Column2 and Column3, click "Merge Columns" and set the separator.

 

Screenshot 2022-05-25 165716.png

vkkfmsft_2-1653469277605.png


3. Select Column4 -> Pivot Column. Then set the [Merged] column as the value and do not aggregate it.

 

Screenshot 2022-05-25 170216.png

vkkfmsft_3-1653469404906.png

 

If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.
Best Regards,
Winniz
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-kkf-msft
Community Support
Community Support

Hi @MRHUP ,

 

I think using a pivot table in Excel can quickly render the matrix.


Or you can try the following M code.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("XY9LDsMgDAXvgtRdFjEhH5asegiUM6Sq1PvXY6r2qRI80MiMTe8pTen+vF4PP1nn1JP5pRFH9bD59qMrgFtWStnCVmiQw3f50AwlbDHxBt5Q1k3EgW32rGIetPyZ6dQIW0UcdOdxFW/Q+EIR76C8zuKlohG7aAPSXacNaPE5HXdgCu3rPd8=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, Column3 = _t, Column4 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", Int64.Type}, {"Column2", type text}, {"Column3", type text}, {"Column4", type text}}),
    #"Filtered Rows" = Table.SelectRows(#"Changed Type", each ([Column2] <> "Group")),
    #"Merged Columns" = Table.CombineColumns(#"Filtered Rows",{"Column2", "Column3"},Combiner.CombineTextByDelimiter("; ", QuoteStyle.None),"Merged"),
    #"Pivoted Column" = Table.Pivot(Table.TransformColumnTypes(#"Merged Columns", {{"Column4", type text}}, "en-US"), List.Distinct(Table.TransformColumnTypes(#"Merged Columns", {{"Column4", type text}}, "en-US")[Column4]), "Column4", "Merged")
in
    #"Pivoted Column"

vkkfmsft_1-1653295778198.png

 

If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.
Best Regards,
Winniz
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi @v-kkf-msft ,

 

This M code works like a charm!! 

 

One question though... How do I alter my original source (is it needed to transform it into this Binary.FromText)? You're using the following statement:

Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("XY9LDsMgDAXvgtRdFjEhH5asegiUM6Sq1PvXY6r2qRI80MiMTe8pTen+vF4PP1nn1JP5pRFH9bD59qMrgFtWStnCVmiQw3f50AwlbDHxBt5Q1k3EgW32rGIetPyZ6dQIW0UcdOdxFW/Q+EIR76C8zuKlohG7aAPSXacNaPE5HXdgCu3rPd8=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, Column3 = _t, Column4 = _t]),

In my code, the source is described as:

let
Source = Csv.Document(File.Contents("\\Ad.gaz.net\wws\\200430\dash\Dashboord2\1.1 Counts).csv"),[Delimiter=",", Columns=4, Encoding=65001, QuoteStyle=QuoteStyle.Csv]),

I've tried, but I can't reproduce the same result with the CSV as source as your code... Can you help me with this? It looks like a small issue?

Hi @MRHUP ,

 

Please follow the steps below.
1. Remove the row where "Group" is located.

vkkfmsft_0-1653468810401.png

vkkfmsft_1-1653468828987.png

 

2. Select Column2 and Column3, click "Merge Columns" and set the separator.

 

Screenshot 2022-05-25 165716.png

vkkfmsft_2-1653469277605.png


3. Select Column4 -> Pivot Column. Then set the [Merged] column as the value and do not aggregate it.

 

Screenshot 2022-05-25 170216.png

vkkfmsft_3-1653469404906.png

 

If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.
Best Regards,
Winniz
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

Hi @v-kkf-msft ,

 

Thank you very much for your detailed explanation and effort! Everything is working perfectly now!

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.