Formula To Solve Columns With Multiple Data Types

muhammad susanto

Well-known Member
Joined
Jan 8, 2013
Messages
2,091
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

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
this should be a simple solution. let me know if this works for what you need
Excel Formula:
=IF(E2="percentage",TEXT(D2,"##.0###"),TEXT(D2,"##"))
 
Upvote 0
Hi..
Thanks buat I think not like this.. Column E as a note that i want data type. Just show that i want not helper column.
How about if there is no col E. What, s formula? Sorry, should be column E not shown
 
Upvote 0
sorry, i misread your first post. this will work for your data you posted. but there's a problem getting excel to recognize what should be a % vs # when it's just above 1. ex- 1.235. for now i have it looking for any # under 2 to convert to a %.
Book1
CDEF
1TargetOutput wantedtype dataformula
20.110.00%percentage10.00%
30.1919.00%percentage19.00%
40.6565.00%percentage65.00%
50.06756.75%percentage6.75%
61.235123.50%percentage123.50%
71000.5100.00whole number1000.50
85050.00whole number50.00
91515.00whole number15.00
106762667626.00whole number67626.00
111234512345.00whole number12345.00
Sheet1
Cell Formulas
RangeFormula
F2:F11F2=IF(C2<2,TEXT(C2,"0.00%"),TEXT(C2,"0.00"))
 
Upvote 0
hi i have to modified your formula into Power Query like this but not work/error, how to fix this problem
Power Query:
if[[Target  Th 2022]<2,Text[[Target  Th 2022]="0.00%",text{[Target  Th 2022],"0.00")
 
Upvote 0
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table4"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Target", type number}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each if [Target]<1 then Number.ToText([Target],"P2") else [Target])
in
    #"Added Custom"
 
Upvote 0
Solution
hi alan..
why not work for me? show message 'the column ' Target' of the table wasn't found'
 
Upvote 0
I don't understand your comment. Below is what my code results in. In the table to the left is the raw/source data. The table to the right is the result of the Mcode I have previously supplied based upon your data supplied.

Book3
ABCD
1TargetTargetCustom
20.10.110.00%
30.190.1919.00%
40.650.6565.00%
56.756.756.75
6123.5123.5123.5
7100010001000
8505050
9151515
10676266762667626
11123451234512345
Sheet1
 
Upvote 0
hi alan..
your formula is correct if to do in Excel as data source
how about if data source in google sheet
here my complete code with data source in google sheet as link
Power Query:
let
    Source = GoogleSheets.Contents("https://docs.google.com/spreadsheets/d/1TO4mggqdC3JzfwD8iKHYEGQUMMkpWhu5O3QyS0vDS-w"),
    #"new adku_Table" = Source{[name="new adku",ItemKind="Table"]}[Data],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Target", type number}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each if [Target]<1 then Number.ToText([Target],"P2") else [Target])
in
    #"Added Custom"

after running code show message "Expression Error: The Column 'Target of the table wasn't found"
how to fix this problem?
Note:
I'm using Excel 2021 & Power BI Desktop Free
 
Upvote 0
Can you provide through a third party the file you are working with. Without seeing the file, cannot determine the issue you are facing.
 
Upvote 0

Forum statistics

Threads
1,223,996
Messages
6,175,857
Members
452,676
Latest member
woodyp

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