Power BI If statement - if-statement

I have created four calculated columns that give True or False for a unique property ref in each row, based on the presence of a registered contact (CMS) on a list (Tele Open, Tele Closed, Written Open, Written Closed). I now need to assign a status to each property ref based on the combination of True False.
I am able to do this using a multiple nested IF AND statement in Excel but am confused about to do this in Power BI.
I haven't yet attempted to do this and need some advice on how to frame the statement, as I am not familiar enough with M Language.
'''
If -- ALL are FALSE = Not Yet Investigated
If -- Tele Open is TRUE = In Progress
If -- Tele Open is FALSE AND Tele Closed is FALSE AND Written Open AND/OR Written Closed is True = In Progress
If -- Tele Open is FALSE AND Tele Closed is TRUE = Closed
'''
The various combination of True False in the categories listed above will produce a Not Yet Investigated, In Progress or Closed status as above.

The basic syntax for a calculated column with an IF statement is
column = if [something] > 1 then [something] else [something else]
you can then nest statement using and and or
column = if [something] >= 1 and [something] <= 10
then "Low"
else if [something] >= 10 and [something] <= 20
then "medium"
else "high"
Hope that helps

Related

Issue with multiple conditions in script editor

I've created a script editor for a google sheet that has multiple tabs. One if statement I can't seem to get working is - If sheet "Employee Evolution" column 8 EQUALS "Disqualified" AND column 13 is NOT EQUAL to "NO DATA", move the row to sheet "Disqualified" I've tried so many different ways to rearrange and can't get it to work.
**function onEdit(event) {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var s = event.source.getActiveSheet();
var r = event.source.getActiveRange();
if(s.getName() == "Employee Evolution" && r.getColumn() == 8 && r.getValue() == "Disqualified" && r.offset.getValue(0,5) != "NO DATA") {
var row = r.getRow();
var numColumns = s.getLastColumn();
var targetSheet = ss.getSheetByName("Disqualified");
var target = targetSheet.getRange(targetSheet.getLastRow() + 1, 1);
s.getRange(row, 1, 1,numColumns).moveTo(target);
s.deleteRow(row);**
I have no coding experience, so I'm having a difficult time understanding javascript documents that explain this stuff. Please help!
Below is the link to my spreadsheet
https://docs.google.com/spreadsheets/d/1vp46hMbmB5968cRW2BGhS66qqNhl91Llk8xeknlRuQc/edit#gid=0
Right now I only have the first if statement and else if statement set up with multiple conditions, but that is not working. When I populate the 8th column (H) with Disqualified and populate the 13th column (M) with anything at all, nothing happens. And, if I populate column H with Qualified and populate column M with Paid Search, nothing happens.
Basically I want the row to move to either the PPC tab or the Disqualified tab. However, I don't want the row to move until both columns H and M are populated with specific text. If column H says "Qualified" AND column M says "Paid Search" the row should move to the PPC tab. If column H says "Disqualified" AND column M says anything other than NO DATA (even Paid Search), the row should move to the Disqualified tab.
The problem I can't get past is that I need to have each if statement look at both columns before executing true.
I hope this makes sense and thank you for your help.
It's not possible to define if that if should be working or not based just on the code as we don't have that spreadsheet you're using.
But I do notice some things that maybe are wrong on yout assumptiong, for this break that if into :
s.getName() == "Employee Evolution" => Checks if the current sheet that you have active is called "Employee Evolution"
r.getColumn() == 8 => checks if the current column that you have active is column number 8 (column h)
r.getValue() == "Disqualified" => checks if the current cell that you have active is equal to Disqualified (must matcha case as well)
r.offset.getValue(0,5) != "NO DATA") => Checks if column offset by 5 (will be equal column 13 indeed) is different then "NO DATA" (also must match case)
And of course as this function is onEdit, so this code will only run when you change something on the spreadsheet.
So I suppose by reading that code is that whenever someone changes column 8 to "Disqualified" (must match the capital letters as well) and all the other criterias match, it should be moved to "Disqualified" sheet. Pay attention to all the case sensitive scenarios you have.
I think overall the code seems fine. Share the spreadsheet so we can check what might be going wrong.
PS: by something being active I mean that your cursor is clicked/selected that thing

IF Statement with multiple conditions and an overriding value

Thanks in advance for helping with this.
I have an issue where this I need the following formula to calculate this- i would advise seeing the picture in the link to fully understand the question (as I'm probably not going to explain myself!);
Calculating Risk Score
Condition 1: If Blood Result is less <=9 or Score <=6 or Tumour Size = <5mm show as text value Low
Condition 2 : If Blood Result 10-20 or Score = 7 or Tumour Size 5mm-9mm show as text value Medium
Condition 3: If Blood Result >=20 or Score = 8 or Tumour Size >=10mm show as text value High
The issue I am having is that any person can have a value from any of the condition, but I need to display the overriding value.
Example:
Blood Result = 5 (condition 1)
Score = 7 (condition 2)
Tumour Size = 10mm (condition 3)
SHOW VALUE: HIGH.
The problemn i'm having is that when I'm doing IF statements, as condition 1 of blood result is True, its always displaying Low without looking at the other values which could overwrite it.
I have only tried nested IF statements with AND OR in them, but no luck.
See examples of values
you can do one thing for that type condition
store your message in one variable, for example, var = msg
if condition 1 true assign msg = "Low"
if condition 2 true assign msg = "Medium"
if condition 3 true assign msg = "High"
after checking all conditions print your message.
I hope this will help you

How can I create a checkbox filter on c++

I'm having a problem that seems way more easy than it is. I think its more of an algorithmic problem than a coding one.
EDIT:
Imagine you have a database with a name and N boolean parameters, like if the person is blonde or not, if the person likes baseball or not, if person have a smartphone or not etc...
How could you print the name of someone that likes baseball AND is blonde, but doesn't matter if any of the other N parameters are true of false? How can I do that without having to write a test for every single of the (N^2)-1 possibilities?
I created a dictionary that maps a string to a struct with 4 boolean variables and some strings.
I want the user to select which booleans are important to them and return only the information that is true for all variable that he chose.
Something like a checkbox which you can use to filter a column in excel.
For instance if a user chose variables 1 and 2, I would like to know if there is a better way to return the result rather than testing every one of the 16 possibilities, like:
void filter(map<string, Mystruct> Mydictionary, bool bool1, bool bool2, bool bool3, bool bool4){
if(bool1 == true && bool2 == true && bool3 == false && bool4==false){
cout << Mydictionary.bool1Info << Mydictionary.bool2Info
if(bool1 == true && bool2 == false && bool3 == false && bool4==false)
...
Even more, for me its only important to test the booleans that the user picked up, so even if he didn't choose boolean3, it's not important to test if its true or false.
Any ideas?
I would be very glad if anyone could help me with this one
I can help you with your algorithm part ,
instead of checking all 16 possibilities just check 4 conditions separately for bool1,2,3,4 and print their info if they are true.
This way you can complete your task with only 4 if statements.
Hope this answers your query.

IF Formula returning error or not doing a section of the formula

I have a formula in my report to select a field based on requirements:
if not isnull({EXT_TBL.EXT_KEY_TYPE}) then
(if {EXT_TBL.EXT_KEY_TYPE} = "SO" and {EXT_TBL.EXT_ACTION_FLAG_9} = "Y"
then {EXT_TBL.EXT_TEXT})
else '0'
When I run the report it works ok until I try to load a specific page. When I try to load the page I get an error of 'The string is non numeric'. The formula is called in another formula:
{COR_TBL.COR_EXPECTED_DATE} + 2 + ToNumber({#FRM_NOTES})
I have ran the query on the server of:
SELECT * FROM EXT_TBL WHERE EXT_KEY_TYPE = "SO" AND EXT_ACTION_FLAG_9 = "Y";
This returned me two rows of data. I have narrowed it down to a specific entry that is causing the issue, but in the database the row has N in the field action flag 9 instead of Y so it shouldn't be throwing me the error in my report.
The action field 9 is flagged on only two records both of which contain a 7 in the EXT_TEXT feild so I have no idea why I am getting the error.
I also tried a nested if statement of:
if not isnull({EXT_TBL.EXT_KEY_TYPE}) then
(if {EXT_TBL.EXT_KEY_TYPE} = "SO" then (if {EXT_TBL.EXT_ACTION_FLAG_9} = "Y"
then {EXT_TBL.EXT_TEXT}))
else '0'
But it still gave me the same error.
Thanks
I was able to fix the issue by removing the nested if statement and just putting all the conditions in the original statement:
if not isnull({EXT_TBL.EXT_KEY_TYPE}) AND {EXT_TBL.EXT_KEY_TYPE} = "SO"
AND {EXT_TBL.EXT_ACTION_FLAG_9} = "Y"
THEN {EXT_TBL.EXT_TXT} ELSE '0'
This seems to have fixed the issue.

Rails unexpectedly creating duplicated records

I need to create a new market "3.5" when the "0.5" closed. The problem is, for some reason, many times, and only on the live server it created duplicaded "3.5", exactly at the same time when it closed the 0.5 and opens the first 3.5. Is there any way to prevent duplicated records from being created? The majority of times it creates single records, but for some reason I can't figure out, sometimes it messes up.
Here is part of the problematic code:
######CLOSE 0.5 / OPENS 3.5
if self.markets.find_by_name('0.5') != nil then
if result.sum >= 1 && (self.markets.find_by_name('0.5').status == "live" || self.markets.find_by_name('0.5').status == "pre-live")
if self.markets.find_by_name('0.5').settle_temp.to_i == 6
selection = "Over 0.5 Goals"
if self.markets.find_by_name('0.5').status == "live" || self.markets.find_by_name('0.5').status == "pre-live"
self.markets.find_by_name('0.5').close(selection)
end
if self.markets.find_by_name('3.5') == nil then
self.markets.create!(name: "3.5", status: "live")
end
else
self.markets.find_by_name('0.5').increment!(:settle_temp)
end
end
end
Don't know your exact situation, but maybe you could add unique constraint
on name and event_id fields pair? For example in the migration you could write:
add_index :markets, [:event_id, :name], :unique => true
In this way you'll be sure that there is just one markets record with desired name value.