Formula To Solve Columns With Multiple Data Types

muhammad susanto

Well-known Member
Joined
Jan 8, 2013
Messages
2,079
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
hi all..

i have problem currently within my dataset there is a column that contains both percentage & numerical data types.
my sheet name is 'new adku' with name field 'Target'
i want to calculate but keep in different types.
i want to decimal number convert to be percentage number and number to be whole number
here the illustration layout
Book1
CDE
1TargetOutput wantedtype data
20,110,00%percentage
30,1919,00%percentage
40,6565,00%percentage
56,756,75%percentage
6123,5123,50%percentage
710001000,00whole number
85050,00whole number
91515,00whole number
106762667626,00whole number
111234512345,00whole number
new adku


i hope someone would help me getting out this problem..
susant
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
If you are referring to the first table then of course there is no field named "Target", you need to change the field name in Power Query to the name of your field in your sheet. I believe that in this case it is "Target Th 2022". In my example, I used the same field name that you provided in your post. If you expectation is in a different table, then you need to change that field name to match your table field name in the PQ Mcode.
 
Upvote 0
hi alan, i have do change "Target Th 2022" to "Target" but still not work
target_pic.jpg
 
Upvote 0
No you have to change the query to Target Th 2022 and keep the name in your google/excel file.
 
Upvote 0
I have had no success with working with your Google Sheets. I don't have any experience in this arena as I only work in Microsoft products. Good Luck as you will have to wait for someone with both Google Sheets and PQ experience. I cannot get your sheet into PQ nor can I save it as an Excel file. :(
 
Upvote 0
hi alan...
i have create new simple data source in google sheet
your code not fully work, i think the problem in this formula.
here new code
Power Query:
let
    Source = GoogleSheets.Contents("https://docs.google.com/spreadsheets/d/1SPg4Ga6V61_wMw1AmHst0ByzHSI_0tngrcPQj4FmzUw"),
    Sheet1_Table = Source{[name="Sheet1",ItemKind="Table"]}[Data],
    #"Added Custom" = Table.AddColumn(Sheet1_Table, "Custom", each if [Column1]<1 then Number.ToText([Column1],"B2") else [Column1])
in
    #"Added Custom"

i upload result after running the code for decimal number is error. i don't know why maybe formula convert to decimal still in problem.
for whole number is correct but for decimal number is not correct
please, see the image
 

Attachments

  • number problem.jpg
    number problem.jpg
    52.8 KB · Views: 9
Upvote 0
How about this:

Book2
ABCDEF
1TargetTargettype dataTarget x100Output
20,10,1percentage11010%
30,190,19percentage11919%
40,650,65percentage16565%
56,756,75percentage26756,75%
6123,5123,5percentage212350123,5%
710001000whole number1000001000
85050whole number500050
91515whole number150015
106762667626whole number676260067626
111234512345whole number123450012345
Sheet1


Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table2"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Target", type number}}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Changed Type",{{"Target", type text}}),
    #"Added Conditional Column" = Table.AddColumn(#"Changed Type1", "type data", each if not Text.Contains([Target], ",") then "whole number" else if Text.StartsWith([Target], "0,") then "percentage1" else "percentage2"),
    #"Changed Type2" = Table.TransformColumnTypes(#"Added Conditional Column",{{"Target", type number}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type2", "Target x100", each [Target] * 100),
    #"Changed Type3" = Table.TransformColumnTypes(#"Added Custom",{{"Target x100", type text}, {"Target", type text}}),
    #"Added Custom1" = Table.AddColumn(#"Changed Type3", "Output", each if [type data] = "whole number" then [Target] 
else if [type data] = "percentage1" then [Target x100] & "%"
else [Target] & "%"),
    #"Changed Type4" = Table.TransformColumnTypes(#"Added Custom1",{{"Output", type text}})
in
    #"Changed Type4"

Change Target to text type, do a conditional column based on the presence of "," and "0,", change Target back to numbers, do a x100 column to use for one of the data types, finish with a custom conditional column.
 
Upvote 0

Forum statistics

Threads
1,223,574
Messages
6,173,142
Members
452,501
Latest member
musallam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top