What is wrong with my Power BI query (using a parameter)? - powerbi

I'm brand new to using PBI but as far as I can tell, I should be able to substitute a parameter as part of a Direct Query in place of a hard-coded variable...ie
let
Source = Sql.Database("NAMEOFDB", "CMUtility", [Query="sp_get_residentsinfo "& home_name]),.....
instead of
let
Source = Sql.Database("NAMEOFDB", "CMUtility", [Query="sp_get_residentsinfo 'NAME OF HOME'"]),...
However, the parameter-included version just says
DataSource.Error: Microsoft SQL: Incorrect syntax near 'House'.
Details:
DataSourceKind=SQL
DataSourcePath=NAMEOFDB;CMUtility
Message=Incorrect syntax near 'House'.
Number=102
Class=15
"House" is the currently - assigned last word of the home_name variable. What have I done wrong?
PS - I have surmised that I shouldn't need the extra & at the end of the parameter, as I'm not adding anything else to the query, but even with both &s it still doesn't work.

The type of your parameters is text. In SQL, text literals must be quoted, i.e. sp_get_residentsinfo 'NAME OF HOME', but the statement build by you is sp_get_residentsinfo NAME OF HOME.
You should use Text.Replace to escape single quotes in the parameter's value and append a quote before and after it.

Related

replace expression format xx-xx-xxxx_12345678

IDENTIFIER
31-03-2022_13636075
01-04-2022_13650262
04-04-2022_13663174
05-04-2022_13672025
20220099001
11614491_R
10781198
00000000000
11283627_P
11614491_R
-1
how can i remove (only) the "XX-XX-XXXXX_" Part in certain values of a column in SSIS but WITHOUT affecting values that doesn't have this format? For example "21-05-2022_12345678" = "12345678" but the other values i don't want them affected. This are just examples of many rows from this column so i want only the ones that have this format to be affected.
SELECT REVERSE(substring(REVERSE('09-03-2022_13481330'),0,CHARINDEX('_',REVERSE('09-03-2022_13481330'),0)))
result
13481330
but this also affects others values.Also this is in ssms not ssis because i am not sure how to transform this expression in ssis code.
Update : Corrected code in SSIS goes as following:
(FINDSTRING(IDENTIFIER,"__-__-____[_]",1) == 1) ? SUBSTRING(IIDENTIFIER,12,LEN(IDENTIFIER) - 11) : IDENTIFIER
Do you have access to the SQL source? You can do this on the sql by using a LIKE and crafting a match pattern using the single char wildcard _ please see below example
DECLARE #Value VARCHAR(50) = '09-03-2022_13481330'
SELECT CASE WHEN #Value LIKE '__-__-____[_]%' THEN
SUBSTRING(#Value,12,LEN(#Value)-11) ELSE #Value END
Please see the Microsoft Documentation on LIKE and using single char wildcards
If you don't have access to the source SQL it gets a bit more tricky as you might need to use regex in a script task or maybe there is a expression you can apply

Is there any way that I can do format matching within a column in powerBI? ( something similar Fuzzy)

I have a column look like as below.
DK060
DK705
DK715
dk681
dk724
Dk716
Dk 685 (there is a space after Dk).
This is obviously due to human error. Is there any way that I can ensure the format is correct based on the specified format which is two uppercase DK followed by three digits?
Or Am I being too ambitious!!??
Go to the power query editor. Select advance editor and paste this 2 steps
#"Uppercase" = Table.TransformColumns(#"Source",{{"Column", Text.Upper, type text}}),
#"Replace Value" = Table.ReplaceValue(#"Uppercase"," ","",Replacer.ReplaceText,{"Column"})
Note: be sure to replace the "Source" statement into the Uppercase sentence for your previuos step name if needed.
So you will have something like this:
This is the expected result:

RDL 2016 Report Builder skip a line for an optional parameter

I have an RDL template which contains of several parameters. They are all optional and marked:
Allow Null Value
Allow Blank Value ("")
It is important that they are optional since sometimes the address does not contain AddressLine3 (or in fact AddressLine1 or AddressLine2, or even PostCode):
They are all dropped together in one textbox area, and it all works well, but the problem is if I don't pass one of the optional params (AddressLIne2 in the example below) - an empty line is preserved in the report:
Any ideas on how to make that empty line disappear?
The easiest way to do this is to replace the list of 5 parameters with a single expression. Something like this.
=
Parameters!FullName.Value & IIF(IsNothing(Parameters!FullName.Value), Nothing, vbcrlf) &
Parameters!AddressLine1.Value & IIF(IsNothing(Parameters!AddressLine1.Value), Nothing, vbcrlf) &
Parameters!AddressLine2.Value & IIF(IsNothing(Parameters!AddressLine2.Value), Nothing, vbcrlf) &
Parameters!AddressLine3.Value & IIF(IsNothing(Parameters!AddressLine3.Value), Nothing, vbcrlf) &
Parameters!PostCode.Value
This simply concatenates each parameter value with a new line added only if the parameter was not empty.
Demo data
The following shows the same principle applied to some address data from the sample AdventureWorks database
The report shows all address fields for illustration
Which gives the following output

Text.Trim Syntax Meaning

I'm working in a Power BI query, trying to trim whitespace from text.
Looking at Microsoft's M reference, I came across the Text.Trim syntax:
Text.Trim(text as nullable text, optional trimChars as any) as nullable text
I couldn't figure out how to plug it into my query code correctly (where it would actually work) so I did some more searching and came across this:
#"Trimmed Text" = Table.TransformColumns(#"Removed Other Columns",{},Text.Trim),
...which doesn't look anything like Microsoft's syntax but works fine for me as I insert it into my code like this:
let
Source = Banding,
#"Removed Other Columns" = Table.SelectColumns(Source,{"Segment", "Granular Band"}),
#"Trimmed Text" = Table.TransformColumns(#"Removed Other Columns",{},Text.Trim),
#"Removed Duplicates" = Table.Distinct(#"Trimmed Text", {"Granular Band"})
in
#"Removed Duplicates"
My problem is that I don't understand what the line's syntax meaning is. I understood Microsoft's example as meaning basically, trim THIS; where THIS is the text I want trimmed. Pretty straightforward.
But I don't know what the syntax meaning of the line that actually works is. I understand that it says to transform table columns (Table.TransformColumns); but I don't know if the reference to the previous line (#"Removed Other Columns") serves as any real "input" for the Text.Trim or if {} is a reference to all columns in the table, or (more importantly to me) how I would reference specific columns. (I've tried a few approaches for specifying columns and failed every time.) I also don't understand why I don't need any arguments following Text.Trim (like in Microsoft's example).
If someone would translate what the line is "saying" in a manner I can understand, I'd sure appreciate it.
The generated code:
#"Trimmed Text" = Table.TransformColumns(#"Removed Other Columns",{},Text.Trim),
means that you most probably selected all columns and then you selected Transform - Format - Trim.
If you would have selected 1 or more columns, then the names of these columns and the required operations would have been between the {}, like in
= Table.TransformColumns(#"Removed Other Columns",{{"SomeText", Text.Trim}})
Any function that is invoked within Table.TransformColumns, gets the column values automatically supplied from Table.TransformColumns, so in this case: the first argument for Text.Trim (text as nullable text).
The other arguments will use the default value, i.c. space, so by default all leading and trailing spaces are removed.
If you want to use other arguments of Text.Trim within the Table.TransformColumns context, then you need to adjust the code and supply the keyword "each", and use an _ as placeholder for the column values.
For example the next code removes leading and trailing spaces and semicolons:
= Table.TransformColumns(#"Removed Other Columns",{{"SomeText", each Text.Trim(_, {" ",";"})}})

if then statement not working asp

I've been trying every combination to make this if then statement work on my ASP page. I've calling fields from 2 access database, then I need to compare both to see if there is a facility that has a report against them.
At first I was using the facility name as the anchor to both database files. It worked pretty good until there was an issue with double quotes in the name. This code worked
<%
for k=0 to y-1
if (B(1,k)) = facility then
%>•<%=B(2,k)%><br /><%
end if
NEXT
%>
So all I did was add a facility id number in the second database (row 12) since the ID already existed in the first database
<%
for k=0 to y-1
response.write(ID)
response.write("\")
response.write(B(12,k))
if (B(12,k)) = ID then
response.write("TRUE")
%>•<%=B(2,k)%><br /><%
else
response.write("FALSE")
end if
response.write("<br>")
NEXT
%>
as you can see, I've tested that the values are acually the same. The results of this If Then is;
2006225\2006225FALSE 2006225\2007101FALSE 2006225\2006225FALSE
2006225\2004245FALSE 2006225\279025FALSE 2006225\2006225FALSE
2006225\2006225FALSE 2006225\2006225FALSE 2006225\2006225FALSE
Since your example code does not show how your variable named ID is assigned, my first guess would be that this may be due to variables being untyped in VBscript and you may not be assigning the type you are expecting to either the above mentioned variable or your array in the above code. You may want to use forced concatenation to make certain the evaluation is based on string types. You can concatenate an empty string in VBscript to force it to evaluate the whole expression as a string (this is what is also happening when you are writing the output). If it works this way, then most likely your variable may actually be getting assigned to a recordset field rather than a string value or something similar.
if ("" & B(12,k)) = ("" & ID) then