Quick questions on 1)M code and 2)Percentage format, please.
I have a couple of columns in my data that hold decimal numbers, which I can change the format once loaded into the model. My attempt to change the column format to percentage while the data is being pulled is via this code:
The downside of applying this code is that I am creating an additional column, so increasing the space. I am sure there has to be a better way of only transforming the decimal to a percentage format without adding columns? Potentially something around Table.TransformColumnTypes? not sure if that would enable me to do any calculation on the transformed col, or would that action change it into Text?
Why when I convert the column into fixed decimal and change the format to percentage it shows more digits (screen below)? is there a correct way of displaying %?
Thanks for posting your question @Hesham. To receive a resolution in a timely manner please make sure that you provide all the necessary details on this thread.
Here is a potential list of additional information to include in this thread; demo pbix file, images of the entire scenario you are dealing with, screenshot of the data model, details of how you want to visualize a result, and any other supporting links and details.
Including all of the above will likely enable a quick solution to your question.
Apologies for not attaching a sample file. You can see in the sample file that col-copy is duplicate col to test my question. The data is sourced from excel file, which holds these columns in a Number format. When they get loaded into query editor, they are formatted as decimal numbers. When I change the Col5-copy into %, it moves the percentage 2 digits, which made me think I need to divide it by 100. The aim is to change col2,4 and 5 into %.
Assuming the above format step in query edit was done ( I am only changing the data type and not the format), is there a way for it to load into PBI with the % format? I understand the format is more about the appearance of that data only, but it was a question I had in mind.
You can use below power query. The problem to convert the number greater than 1 to percentage will exceed 100%, so you need to divide it by 100 and then convert it to percentage.
let
Source = Excel.Workbook(File.Contents("C:\Users\Anonymous\Desktop\decimal.xlsx"), null, true),
Sheet1_Sheet = Source{[Item="Sheet1",Kind="Sheet"]}[Data],
#"Promoted Headers" = Table.PromoteHeaders(Sheet1_Sheet, [PromoteAllScalars=true]),
#"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"Col1", type number}, {"Col2", type number}, {"Col3", type number}, {"Col4", type number}, {"Col5", type number}}),
#"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each [Col5]/100, Percentage.Type)
in
#"Added Custom"
Below screen shot FYR. Also if it shows in decimal after loading then you change the format here as highlighted.