Power BI Advanced Editor - How to run query if current date is NOT within a list of values? - powerbi

I want to run a query in Advanced Editor, only if the current date is NOT one of the following - 1, 5, 10, 15, 20, 25. Otherwise I dont want the query to run.
I have written the below but I am not getting anywhere very fast:
let
Output = if Date.Day (DateTime.LocalNow()) in (1,5,10,15,20,25) then null else
let
Source = PBILifts
in
#"PBILifts"
What am I doing wrong?
Cheers for all help
Edit: So based on suggestion by #Aleksei I tried below but it doesnt work:
let
output= if List.Contains({1,5,10,15,20,25}, Date.Day(DateTime.LocalNow())) then #table({},{}) else
Source = PBILifts
in
#"PBILifts"
I get the below error:
An error occurred in the ‘’ query. Expression.Error: The name 'Source' wasn't recognized. Make sure it's spelled correctly
Any further help please?

It's PQ, not SQL, so in (1,5,...) syntax is incorrect. Try something like this (assuming, your query's output is table):
= if List.Contains({1,5,10,15,20,25}, Date.Day(DateTime.LocalNow())) then #table({},{}) else YourQuery
or:
let
output = if List.Contains({1,5,10,15,20,25}, Date.Day(DateTime.LocalNow())) then #table({},{}) else PBILifts
in
output

Related

Power BI :: create measure that remove the last 2 characters from column

I have a query that targets our resourceGroupName on Azure.
The resourceGroupName looks like this:
hello-world-customer-prod-rg
hello-world-customer-staging-rg
hello-world-customer-test-rg
hello-world-customer-dev-rg
I want to remove the last rg from each resourceGroupName
For now I tried this:
URL_test1 = Text.Start(SELECTEDVALUE('Usage details'[resourceGroupName]);Text.Lengh('Usage details'[resourceGroupName])-2)
but I receive 'Text.Start' is not a function and Unexpected expression Text.Length
or this:
URL_test2 = RIGHT(SELECTEDVALUE('Usage details'[resourceGroupName]);2)
and I receive Unexpected expression ;
Nothing really seems to work.
What am I doing wrong?
EDIT: this seems working but it returns me the number of characters (17) and not the text:
URL_test3 = LEN(SUBSTITUTE(SELECTEDVALUE('Usage details'[resourceGroupName]),"-rg",""))
I have actually found the solution.
I passed from:
URL_test3 = LEN(SUBSTITUTE(SELECTEDVALUE('Usage details'[resourceGroupName]),"-rg",""))
to:
URL_test3 = SUBSTITUTE(SELECTEDVALUE('Usage details'[resourceGroupName]),"-rg","")
That's why it was showing the number!
It was because of the LEN().

HOW TO MAKE IF AND SEARCH STATEMENT GOOGLE SPREADSHEETS

So i have dropdown (cells J23) and when the dropdown gets the number, i want to show the results number (which is percent cell).
I was use filter, search and if function.
When i was run the if function, it's work. But when i was combine it, it doesn't work.
Here's my function
=filter(F10:G,search(J23,IF(J23 < 10, J23, IF(J23 = 10, 10, IF(J23 > 10, J23))), F10:F))
If you need my excel, you can access my google sheets
Your spreadsheet goal is hard to understand from your current formula. I think that you want the following...
In K21:
=IFERROR(VLOOKUP(J21,F6:G8,2,FALSE))
In K23:
=IFERROR(VLOOKUP(J23,F10:G,2,FALSE))
try:
=ARRAYFORMULA(IFERROR(QUERY(TO_TEXT(A5:C), "where 9=9 "&
IF(I6="",," and lower(Col1) contains '"&LOWER(I6)&"'")&
IF(J6="",," and lower(Col2) contains '"&LOWER(J6)&"'")&
IF(K6="",," and lower(Col3) contains '"&LOWER(K6)&"'")), "no match"))

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.

regexp_similar '^.$' issues in teradata

For data scrubbing I have lot of hard coded values in my program. I am trying to put those values into a table. One of the conditions for this scrubbing is to find the length of the character and code (character_length(name) = 1).
But when I try to emulate the this by using ^.$, it is not catching values like ¿, ¥, Ã
please let me know if I am doing something wrong .
When I run below code and I see this 3 values ¿, ¥, Ã
select name from email_table
where character_length(name) = 1
and name not in
(select name from email_table
where regexp_similar(translate(name USING LATIN_TO_UNICODE WITH ERROR),'^.$', 'i') = 1)
It seems like the issue is due to version.
We have TD14 and TD 15 on different servers and I did following query
select case when regexp_similar('¥','^.$', 'i')=1
then 'Y'
else 'N'
end as output;
In case of TD 14, I get output as 'N' and in case of TD 15 answer is 'Y'.

Rails query works then creates an error

I have a query to retrieve all the spots (times) available on a given date.
#takenspots = Spot.joins(:reservations).where('reservations.date = ?', params[:date])
if #takenspots.any?
#availablespots = Spot.where('id != ?', #takenspots.map)
I use #availablespots to populate a select_list.
I have 4 different spots per day and the query works only 2 times. (2/4 spots)
If a try to book a day where i have 2 spots taken out of 4, it says:
SQLite3::SQLException: near ",": syntax error: SELECT "spots".* FROM "spots" WHERE (id != 1,2)
But I can't understand why it works for the first 2 spots and not the 2 remaining...
Someone got an idea ?
Thank you,
I have no idea why this works actually, but it does, so this might help someone:
#availablespots = Spot.where('id not in (?)',#takenspots.map(&:id))