I have a Actuals column like so:
ID | Airport
------------
A | 98.4
B | 98.0
C | 95.3
I'm attempting to format the numbers above into percentages for a front-end report. I have this written in a switch statement - for ease I'll just write the logic as an IF boolean.
example_measure =
VAR Nums = SELECTEDVALUES(Table[Actuals])
VAR FormatNums = IF(DIVIDE(ROUND(nums,1), nums) = 1,
format(nums,"0%"),format(nums,"0.0%")
-
RETURN
FormatNums
no matter what I do this always returns a number with a floating point value of 1f
so in my raw data of 98.0 I'm expecting the format to return "98%" rather than "98.0%"
the measures are used on individual cards, and are filtered so they can only ever show one value or blank, meaning they will only ever display one value on their own.
I've toyed with using if(nums = int(nums) which should evaluate to true for 98.0 but it I always get false.
There is a simpler way - just use built-in formatting codes:
Formatted Actuals =
VAR x = SELECTEDVALUE(Data[Actuals])
RETURN
FORMAT(x, "General Number") & "%"
Result:
Built-in style "General Number" handles your situation correctly, you just need to add % symbol to the formatted string. No need to test for whole numbers.
To convert a column/measure into percentage, you can simply divide the column by 100 and then format it as a percentage. Use the following steps:
Create a new column/measure: Perc_value = Table[Actuals]/100
Then go into the modelling tab, select the created column/measure and format it as a % and limit the number of decimal places to 0
This should give the view you are looking for. Hope this helps.
Edit:
You can use the below formula to achieve the desired result:
Column4 = IF('Table'[Column2]-ROUND('Table'[Column2],0)=0,FORMAT('Table'[Column2]/100,"0%"),FORMAT('Table'[Column2]/100,"0.0%"))
Replace Column2 withyour field and you should be good to go.
Related
I'm new in this world. As you can see in the picture, I key in function at B1 and I want B1 to return 1 if A1 data is time. But it kept of giving me 0. At the same time, I want if there are no value or N/A, it must return 0. What should I key in? I do understand that if using =ifna("A","1","0"), but that still does not return me anything for if there are any data.
Format your column A to "Time"
Paste formula to B2: =IF(ISDATE(A1);1;0)
Note: I'm using Norwegian formatting/settings. For english formatting/settings, change ";" with "," in formula.
Why your formula won't work:
Since you use "" with your hh:mm:ss like this: "hh:mm:ss" - you're asking your formula to look for exactly that. Your formula will only return TRUE if A1 = hh:mm:ss (in text)
In IF-statements, do not use "" for returning numbers og TRUE/FALSE.
Your formula: if(A1="hh:mm:ss","1","0)
What needs to be changed in TRUE/FALSE part: if(A1="hh:mm:ss",1,0)
-- Tho, you need to ask if A1 is a date: =IF(ISDATE(A1),1,0)
To count for N/A - put IFERROR in formula: =IFERROR(IF(ISDATE(A1),1,0)0)
The table is like the image:
I need to keep the NaN as empty but when I use IFERROR() and put blank() in the ValueifError it just deletes the entire row which I dont want. Is there any way to replace NaN with a blank space
I used the dax below:
oscar wins = SUM(Films[OscarWins])/SUM(Films[OscarNominations])
Try using the DIVIDE function instead of '/' operator.
Ex: Test = DIVIDE(Col1,Col2)
You can handle the case when denominator is 0 as below. This will simply check, if the denominator is 0, it will return BLANK(). Other case it will return the result from normal calculation.
oscar wins =
IF(
SUM(Films[OscarNominations]) = 0,
BLANK(),
SUM(Films[OscarWins])/SUM(Films[OscarNominations])
)
It is likely your SUM(Films[OscarNominations]) is returning 0, resulting in a divide by zero.
For your IFERROR fix, right click on a field value in your visual and select "Show items with no data".
Alternatively, on error, return 0. It really depends on how you want your audience to interpret the data. In reality, it is Not A Number (NaN)...
Source data:
Market Platform Web sales $ Mobile sales $ Insured
FR iPhone 1323 8709 Y
IT iPad 12434 7657 N
FR android 234 2352355 N
IT android 12323 23434 Y
Is there a way to evaluate the sales of devices that are insured?
if List.Contains({"iPhone","iPad","iPod"},[Platform]) and ([Insured]="Y") then [Mobile sales] else "error"
Something to that extent, just not sure how to approach it
A direct answer to your question is
let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
SumUpSales = Table.AddColumn(Source, "Sales of insured devices", each if List.Contains({"iPhone","iPad","iPod"}, _[Platform]) and Text.Upper(_[Insured]) = "Y" then _[#"Mobile sales $"] else null, type number)
in
SumUpSales
However, I would like to stress you few things.
First, it's better to convert values in [Insured] column to boolean first. That way you can catch errors before they corrupt your data without you noticing. My example doesn't do that, all it does is negating letter case in [Insured], since PowerM is case-sensitive language.
Second, you'd better use null rather than text value error. Then, you can set column type, and do some math with its values, such as summing them up. In case of mixed text and number values you will get an error in this and many other cases.
And last.
It is probably better way to use a pivot table for visualizing data like this. You just need to add a column which groups all Apple (and/or other) devices together based on the same logic, but excluding [Insured]. Pivot tables are more flexible, and I personally like them very much.
I have a bit of a unique situation, I have a column of data that has text values:
Column
sdfsadf42lkjdflk
skld35kdfosdffj
kdfjsi78ldsfjoi
Result should look like:
Column
42lkjdflk
35kdfosdffj
78ldsfjoi
Is there a way to cut out everything before a number? A generalized way would be nice in the event that number currently not included can still be evaluated for (the instance of a number always being used is the only constant)
You can try finding the index and then slicing the str using the same index. I will show you with an example.
var str = "skld35kdfosdffj";
var firstDigit = str.search(/\d/);
str = str.slice(firstDigit,str.length);
console.log(str);
Assuming your column is named ColumnName, in powerquery, add custom column with formula
= Text.RemoveRange([ColumnName], 0, Text.PositionOfAny([ColumnName],{"0".."9"}))
Can I select a certain row/column combination in coldfusion without doing a query of queries? For example:
Some Query:
ValueToFind | ValueToReturn
String 1 | false
String 2 | false
String 3 | true
Can I somehow do #SomeQuery["ValueToFind=String 3"][ValueToReturn]# = true without doing a query of queries ? I know there's code out there to get a certain row by id, but I'm not sure how or if I can do it when I need a string as the ID
If this can't be done, is there a short hand way to set up a coldfusion function so I can use something like FindValue(Query, "String 3") and not have to use ?
You can treat a query column as an array.
yourRow = ArrayFind(queryName['columnName'], "'the value you seek'");
If you get a zero, the value you seekis not there.
Edit starts here:
For values of other columns in that row, simply use that variable.
yourOtherValue = queryName.otherColumnName[yourRow];
A small modification to Dan's code, you can find the column value using the code below
yourVaue = SomeQuery["ValueToReturn"][ArrayFind(SomeQuery['ValueToFind'], "String 3")]