if condition not reevaluating on google sheet based off NOW() and time - if-statement

I have a cell P2 with the NOW() function and formatted to display time.
=NOW()
I also have another cell with a If condition that evaluates the time from P2 now() compares against a set time 1400 in this case and sets the Cell to be TRUE or FALSE
=if(P2<time(14,0,0),TRUE,FALSE)
I set the spreadsheet's refresh rate to be every minute.
Before 1400, I was expecting it to set to TRUE
Once the time is past 1400, I was expecting the cell to update to FALSE
This is where I see a problem, the cell doesn't reevaluate the time based off the spreadsheet refresh settings. If I paste in the same formula it'll reevaluate at the new cell to show the expected results.
How can I get the spreadsheet to reevaluate the time based off the NOW() and Time functions?
Thanks

NOW is not just a time it is a today's date and now's time. So, you need to subtract TODAY from it to get only the time. Date time is a number: date part is the integer-part of a number, time - fractional-part.
One way to drop the date would be to use MOD(NOW(), 1).
=IF(MOD(P2, 1) < TIME(14, 0, 0), TRUE, FALSE)
Or better leave it as it was and just put =MOD(NOW(), 1) in P2.
Here is a little demonstartion:
I suggested before to use NOW() - TODAY() which looks clear, but I think it could give you more then 24 hours on the edge of a day. So, better not use this method.

try directly:
=IF(TIMEVALUE(NOW())<TIMEVALUE(TIME(14, 0, 0)), TRUE)
and also set:

Related

Display a blank instead of a 0 on a table on Power BI

I need to develop a report with a table that includes several dimensions and displays a sales revenue measure. Most of the times this measure throws a zero, but the user wants to visualize a blank space instead. I have searched around, but I couldn´t find anything that gives me support. So if anyone has experimented this or found a workaround I would thank you for your time.
You could use a IF condition to replace 0 with blanks. For example, if you are summarizing a field called "Sales" the following formula would work:
Measure = IF(Sum(Sales)=0,"",Sum(Sales))
Hope this helps.
Adding the additional option based on Ricardo's suggestion:
Measure = IF(Sum(Sales)=0,Blank(),Sum(Sales))
If you have a measure [Measure] and you want to replace 0 with a blank, you can do the following:
MeasureReplaceBlank =
VAR Measure = [Measure]
RETURN IF ( Measure = 0, BLANK(), Measure )
Note that since I stored the calculation of [Measure] as a variable, I don't need to call it twice (once for the condition and once for the True branch of the IF function).

How to check if a criterion is present in a range of cells in Google Sheets?

I am trying to collect time information on a maintenance worksheet for work that was completed outside of the current work week.
Right now I am referencing each date cell individually and it works but it's a massive and clunky formula. I've tried out a number of things I haven't used before but none of them seem right. COUNTIF will not work because I need to sum the range based on the value in question not being present in the current range of dates.
=SUM(SUMIFS(WT!$O$4:$O$100,WT!$C$4:$C$100,CONCATENATE("<>",$B$9),WT!$C$4:$C$100,CONCATENATE("<>",$B$10),WT!$C$4:$C$100,CONCATENATE("<>",$B$11)...
As I said, the output is correct but I want it to be more easily transferable and scale-able in the case of adding another worker.
you can do it like this in C18:
=ARRAYFORMULA(SUM(IFERROR(QUERY({WT!$C4:$F100, INDIRECT("WT!"&
ADDRESS(4, MATCH(C7, WT!$A3:3, 0), 4)&":"&
ADDRESS(100, MATCH(C7, WT!$A3:3, 0), 4))},
"select Col4
where Col5 is not null
and not Col1 matches '"&TEXTJOIN("|", 1, TEXT($B9:$B17, "yyyy-M-d"))&"'", 0))))

Checking if any value in Column is equal to Todays Date

I'm working in Google Sheets and I am trying to determine if any value of dates listed in the column is equal to Today's Date.
I have tried using the COUNTIF formula the ISDATE formula and the IF formula against the value of TODAY() and nothing seems to be working right.
=IF('Invoices-Quickbooks-Data'!L:L,ISDATE(TODAY()),true)
This formula actually works the best for me. I would expect it to calculate if any of the values equal Today's Date. Ironically this tells me that the answer is TRUE even when none of the dates actually match Today's date so I am not sure what is going on.
First, the reason why your formula is always returning true is because ISDATE(TODAY()) will always return true (when is today not a date?) and furthermore, you can't use an IF statement like that to query a whole column. The first argument to IF is a condition, and a column range is not a condition.
To apply a function over a range, you want to use an ARRAYFORMULA. Here is how you would check a range of cells to see if any value in the column (or range) contains a date equal to today:
=IFERROR(VLOOKUP(TRUE,ARRAYFORMULA(IFERROR(DATEVALUE(A:A)=TODAY(),FALSE)),1,FALSE),FALSE)
Just replace A:A with the range you want to check. The return of an ArrayFormula is an array, which is why I have to use VLOOKUP to check for any TRUE values inside it.
Advanced solution:
A really cool feature in sheets is the query() function, which essentially lets you run a SQL-like query over a range of cells. I like it because it makes formulaes very readable - for example, the entire ARRAYFORMULA solution above can be replaced with:
=IFERROR(QUERY('Invoices-Quickbooks-Data'!L:L,"select count(L) where dateDiff(L,now()) = 0 label count(L) ''",-1) > 0,FALSE)
you can check it with just simple IF formula:
=ARRAYFORMULA(IF(LEN(A2:A), IF(A2:A=TODAY(), TRUE), ))
=ARRAYFORMULA(IF(A2:A=TODAY(), TRUE, ))

How to check spreadsheet cell value with MATCH without triggering NOW() function?

Trying to create a table that checks if the room key is already taken.
Google spreadsheet link.
An employee selects or enters the value into F2 cell. The formula in the G2 cell =IF(ISERROR(MATCH(F2,C4:C350,0)), "Brīvs", "Paņemts") tests whether the key is taken or not. The formula runs through C column and tests for the value.
While matching, it is also triggering the formula in B4 cell. Formula in B4 being =IF(C4>0, now(), "")
Issue is, every time an employee selects/enters the value, the MATCH function triggers the now() function and overrides the newest time if it matches the search criteria.
Is there a way of testing for the value without invoking the now() function so that the time stays as it was? Limiting recalculation counts in spreadsheet settings does not aid since an employee may not enter the value correctly from the 1st time.
Tried putting the value into another cell by "=" to nearby cell and =cell(contents, cell coordinate), but these refer back to the original values and Spreadsheet would recalculate all the references.
Thanks to cOde for providing the hint.
The code below is modified to the following needs. Since the sheets will be subsequently added, the SHEETNAME variable is taken out. I have also added the isBlank option at the end, so that if there is no value in the cell, the timestamp is erased.
/**
* Creates a Date Stamp if a column is edited.
*/
//CORE VARIABLES
// The column you want to check if something is entered.
var COLUMNTOCHECK = 3;
// Where you want the date time stamp offset from the input location. [row, column]
var DATETIMELOCATION = [0,-1];
function onEdit(e) {
SpreadsheetApp.getActiveSpreadsheet();
var ss= SpreadsheetApp.getActiveSheet();
var selectedCell = ss.getActiveCell();
//checks the column to ensure it is on the one we want to cause the date to appear.
if( selectedCell.getColumn() == COLUMNTOCHECK) {
var dateTimeCell = selectedCell.offset(DATETIMELOCATION[0],DATETIMELOCATION[1]);
dateTimeCell.setValue(new Date());
}
if (selectedCell.isBlank()) {
dateTimeCell.setValue("");
}
}

PowerBI/DAX: Unable to correctly compare two dates

I have this custom date that I created as a measure:
Start Date = DATE(YEAR(MAX(Loss[dte_month_end]))-1,12,31)
So this part looks fine in PowerBI and seems to be the right format.
So now I created a new column where I'm going through my data to check whether a record is equal to my "Start Date" as defined above.
IsStart = IF(Loss[dte_month_end]=[Start Date], TRUE, FALSE)
but the weird thing is that all records are evaluated to false.
I know this is actually not the case in my actual data, and I could find actual records with dte_month_end = 12/31/2017 as shown above.
Can someone help me understand why the IF statement would not be able to evaluate this correctly? I initially thought that this may be a case of the DATETIME format being inconsistent - but I purposefully changed both formats to be the same to no avail.
Thanks.
Edit1----------- FYI:
This is the format that my dte_month_end field has:
Edit2 --
I tried changing the dte_month_end format to Date instead of DateTime, and it still doesn't seem to work:
This is happening because you are using a measure inside of a calculated column. When you do this, the filter context for the measure is the row context in the table.
To fix this, you need to modify the filter context for your measure. For example:
Start Date = DATE(YEAR(CALCULATE(MAX(Loss[dte_month_end]), ALL(Loss))) - 1, 12, 31)
or
Start Date = DATE(YEAR(MAXX(ALL(Loss), Loss[dte_month_end])) - 1, 12, 31)
If you don't do this, the MAX only looks at the current row, rather than all the rows in the table.