Creating a calculated boolean field based on thresholds - powerbi

I'm analysing some data using Power BI, and I have a field in the data called deflection. Normally the value in the field is 0, but a small number of results will have other values ranging from -360 to +360.
Within the dataset, any value > 2 or < -2 might be significant.
I would like to create a new boolean value to indicate if the deflection value is significant or not.
Any value between -2 and + 2 is NOT significant - bSigDeflection = False
Any other value - bSigDeflection = true
How do I approach this?
I have started by using an abs(deflection) value in the sql query, just to keep everything positive. I could write a sql CASE statement that would probably work but I feel that there must be a simpler way to achieve this in Power BI that I am missing.
Any suggestions, clever people?
Thanks

You may use TransformColumns to replace the value with the bool. Or you can use the same code with Table.AddColumn if you want to keep the original value.
let
Source = ...,
coerceDefelectBool = (input) as logical =>
if input < 2 or input > 2 then true else false,
Final = Table.TransformColumns(
Source,
{"Deflection", coerceDefelectBool},
null, MissingField.Ignore
)
in
Final
If you wanted a measure, not a DAX calculated column, you can try something like this.
[ bSigDeflection ] = SWITCH (
TRUE,
SELECTEDVALUE( [Table].[Deflection] ) > 2, TRUE(),
SELECTEDVALUE( [Table].[Deflection] ) < 2, TRUE(),
FALSE()
)

Related

'LOOKUPVALUE' does not support comparing values of type Number with values of type True/False

I'm quite new in using DAX in PowerBi and I need to perform the following dax function:
Latest Detailed =
LOOKUPVALUE (
EXAM_REPORT[ACTUAL_EXAM_DATE],
EXAM_REPORT[CES EXAM.EXAM_TYPE_SR_KEY],
EXAM_REPORT[CES EXAM.EXAM_TYPE_SR_KEY] = 2,
EXAM_REPORT[CES EXAM.EXAM_SIGNOFF_DATE],
ISBLANK ( EXAM_REPORT[CES EXAM.EXAM_SIGNOFF_DATE] ) = FALSE,
EXAM_REPORT[ASSET_GUID],
[ASSET_GUID] = [ASSET_GUID]
)
Unfortunately I keep getting this error:
Function 'LOOKUPVALUE' does not support comparing values of type Number with values of type True/False. Consider using the VALUE or FORMAT function to convert one of the values.
I’ve tried converting everything to strings and also tried VALUE as well, but nothing changes.
Could you please help me? How can I do in a way that all the values share the same datatype?
LOOKUPVALUE has a different signature than what you are using:
LOOKUPVALUE(
<result_columnName>,
<search_columnName>,
<search_value>
[, <search2_columnName>, <search2_value>]…
[, <alternateResult>]
)
Your Code:
LOOKUPVALUE(
<result_columnName>,
<search_columnName>,
<search_columnName> = <search_value>
)
And FALSE must be FALSE(), but the condition is inappropriate anyway.

i need to replace NaN with blank space where the operation fails in dax power bi

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)...

PowerBI empty values row not displayed

I have a confusing mystery...
Simple DIVIDE formula works correctly. However blank rows are not displayed.
I attempted a different method using IF, and now the blank row is correctly displayed.
However this line is only displayed if I include the IF formula (which gives a zero value I don't want).
Formula 1:
Completion % =
DIVIDE(SUM(Courses[Completed]),SUM(Courses[Attended]),BLANK())
Formula 2:
Completion % with IF =
IF(SUM(Courses[Attended])=0,0,DIVIDE(SUM(Courses[Completed]),SUM(Courses[Attended])))
With only the DIVIDE formula:
Including the IF formula:
It appears that Power BI is capable of showing this row without error, but only if I inlude the additional IF formula. I'm guessing it's because there is now a value (0) to display.
However I want to be able show all courses, including those that have no values, without the inaccurate zero value.
I don't understand why the table doesn't include these lines. Can anyone explain/help?
The point is very simple, by default Power BI shows only elements for which there is at least one non-blank measure.
The DIVIDE operator under-the-hood execute the following:
IF(ISBLANK(B), BLANK(), A / B))
You can change its behaviour by defining the optimal parameter in order to show 0 instead of BLANK:
DIVIDE(A, B, 0) will be translated in the following:
IF(ISBLANK(B), 0, A/B))
Proposed solution
Those mentioned avobe might all be possible solutions to your problem, however, my personal suggestion is to simply enable the option "show item with no data" in your visualization.
While DIVIDE(A, B, 0) will return zero when when B is zero or blank, I think a blank A will still return a blank.
One possibility is to simply append +0 (or prepend 0+) to your measure so that it always returns a numeric value.
DIVIDE ( SUM ( Courses[Completed] ), SUM ( Courses[Attended] ) ) + 0

DAX to Test for Whole Number

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.

Iterate through variables in a regression in SAS/JMP

I'm trying to take a set of independent variables and test if they are (statistically significantly) differently-correlated to two groups of data.
I've been advised that the way to do this in JMP is to make a series of linear regressions like the following,
result = group + varA + group*varA
and then examine the significance of the interaction effect, e.g., the "Prob > F" column in this "Country*Displacement" example: http://i.stack.imgur.com/EcCdd.png (I don't have the reputation to post an image.)
Now, I need to be able to switch out one of these variables; that is, for a list of ~350 variables, say varA, varB, etc., I need to run the following regressions,
result = group + varA + group*varA
result = group + varB + group*varB
result = group + varC + group*varC
...
and get the significance of that interaction effect. Previous attempts to scripting have resulted in ~350 results windows, or ~350 model dialogs . . . any advice would be appreciated.
Edit:
For example, using the Airline Delays JMP sample data set, this is the result from one of the steps: http://i.stack.imgur.com/HVFL8.png. I need to extract the significance of the interaction effect (the 0.1397 under Effect Tests) for each of a set of variables; for example, interchanging the "Distance" variable with "Elapsed Time". But I need to interchange this variable for each in a set of ~350.
Assuming you know how to for through these values. This will get you the effect P Values.
fit = Fit Model(
Y( :Arrival Delay ),
Effects( :Distance, :Day of Week, :Distance * :Day of Week ),
Personality( Standard Least Squares ),
Emphasis( Minimal Report ),
Run(
:Arrival Delay << {Lack of Fit( 0 ), Plot Actual by Predicted( 0 ),
Plot Residual by Predicted( 0 ), Plot Effect Leverage( 0 )}
)
);
hash = associative array(fit<<Get Effect Names, fit<<Get Effect PValues);
value = hash["Distance*Day of Week"];
then just close fit << Close window; and move on to the next parameter.