I keep having this error when using Bing Maps API, as anyone encountered this issue?
I resolved the issue. I kept getting the authentication issues because there was a "#" in the address line. If an apt or street number is written as #.., it will keep asking for credentials. Just change the # to No and it works fine.
I have. What have you done exactly? Why is it complaining about credentials?
Here is an example function I used at the time. It fetches the Coordinates for a desired city. You can paste it in Advanced Editor and make a function. Just make sure to insert your api key.
let
fxGetCoords = (city as text) =>
let
Source = Json.Document(
Web.Contents("http://dev.virtualearth.net/REST/v1/Locations?query=" &
city & "&includeNeighborhood=0&key="xxxxxx-insert-your-key-here-
xxxxxxxx")
),
resourceSets = Source[resourceSets],
resourceSets1 = resourceSets{0},
resources = resourceSets1[resources],
resources1 = resources{0},
point = resources1[point],
coordinates = point[coordinates],
#"Converted to Table" = Table.FromList(coordinates, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
#"Transposed Table" = Table.Transpose(#"Converted to Table"),
#"Renamed Columns" = Table.RenameColumns(#"Transposed Table",{{"Column1", "Latitude"}, {"Column2", "Longitude"}}),
#"Changed Type" = Table.TransformColumnTypes(#"Renamed Columns",{{"Latitude", type number}, {"Longitude", type number}})
in
#"Changed Type"
in fxGetCoords
If this works the problem is not your credentials, but how you are using them.
Related
Not well versed in PBI formulas but kinda know what I'm looking for. I have a comment field that can be long so what I'm trying to do is
if text.length([comment] > 45) then text.range(text.combine([comment],"..."),45) else [comment]
Some of the comments field will be null as well. I've tried different variations of this and just can't see to get it right. Appreciate any help. Thanks.
Note, M is case sensitive, so text.length() Null and text.combine will not work. You have to use Text.Length() , Text.Combine() , null, etc.
Try this:
= try if Text.Length([comment])>45 then Text.Start([comment],45)&"..." else [comment] otherwise null
You can use add that as part of a new custom column:
let Source = #table({"comment"},{{"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"},{"Bus"},{null}, {"Car Log"}}),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"comment", type text}}),
#"Add Custom Column" = Table.AddColumn( #"Changed Type", "Custom", each try if Text.Length([comment])>45 then Text.Start([comment],45)&"..." else [comment] otherwise null)
in #"Add Custom Column"
Or transform the existing column:
let Source = #table({"comment"},{{"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"},{"Bus"},{null}, {"Car Log"}}),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"comment", type text}}),
#"Transform Column" = Table.TransformColumns(#"Changed Type",{{"comment", each try if Text.Length(_)>45 then Text.Start(_,45)&"..." else _ otherwise null, type text}})
in #"Transform Column"
I am working on building reports in Power BI. I have created various reports using formulas etc. Now I am going to add another source of data that has the same number of columns as my previous source.
Source Data
Source 2
I have added some formulizations and new columns that I want exactly to replicate onto the new source which has the same column names, type but different data.
Is there any way that I can do this? Any help would be highly appreciated
If I understand your question correctly, you want two connections in one query.
For this purpose you define a parameter.(For example "Connection")
If its value was 1, the query loaded from source 1 and if its value was 2 was loaded from source 2.
let
MySource = if Connection=1 then
let
Source = source_1,
#"Changed Type" = ...,
in
#"Changed Type"
else
let
Source = source_2,
#"Changed Type" = ...,
in
#"Changed Type",
#"Removed Columns" = Table.RemoveColumns(MySource, {"Column3"})
#"Removed Columns1" = ...
in
#"Removed Columns1"```
I am trying to create lists of data using dynamic columns, fetching the column name and appending it to the table.
Here is the problem as this step is throwing error:
Expression.Error: We cannot apply operator & to types Table and Text.
Details:
Operator=&
Left=[Table]
Right=Test1
Code:
let
Source = Excel.Workbook(File.Contents("C:\Users\Sivakumar A\Desktop\Power BI\test1.xlsx"), null, true),
Sheet2_Sheet = Source{[Item="Sheet2",Kind="Sheet"]}[Data],
#"Promoted Headers" = Table.PromoteHeaders(Sheet2_Sheet, [PromoteAllScalars=true]),
#"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"Test1", type text}, {"Test2", Int64.Type}, {"Test3", Int64.Type}, {"Test4", Int64.Type}}),
#"Col Names" = Table.ColumnNames(#"Changed Type"),
#"Generate" = List.Generate(() => [i=-1,x= Table.FromList(#"Col Names",Splitter.SplitByNothing())],
each [i]<List.Count(#"Col Names"),
each [
i=[i]+1,
x=#"Promoted Headers"&#"Col Names"{i}
],
each [x])
in
Generate
I need to extract the column names and append it to the talble and execute in loop
Any help is appreciated.
My requirement is to append the column names dynamically to the table using list.generate and generate the list of values out of it.
I was able to resolve the issue using Double Quotes 3 times.
"Table.Distinct(Table.FromList(#"&"""Sheet2 (2)"""&"["&#"Col Names"{i}&"], Splitter.SplitByNothing(), null, null, ExtraValues.Error))"
I'm trying to find the Country lat, long to visualize the Country in the world map on Power BI.
Please suggest me the procedure to find lat, long on PowerBI or any APIs available from PowerBI tool.
First, we have to use any API service to get lat-long
Create bingmapsportal account
Here I'm using Microsoft bing maps API services Go to BingMapsPortal account to SignUP account if you already don’t have
After SingUp we have login it will redirect to dashboard
Generate key
Once we reached dashboard page we have to generate key to use restful api services
Once keys is ready then refer the document to find the api to get the lat and long based on given country
We use below give url to get lat and long in xml format
http://dev.virtualearth.net/REST/v1/Locations/india?o=xml&key=AjvYaTSLr8dsu4eqeDt0OigOZ_xuTkdVMUQCDMc0gcDPm
Use virtualearth API service to get lat and long of the location
Once data is available then we have to convert that into tabular form
Create Invoke Custom function
If we need to get multiple countries' dashboard then we have to write custom invoke functions such as given below and save.
= (location) =>
let
Source = Xml.Tables(Web.Contents("http://dev.virtualearth.net/REST/v1/Locations/"&location&")?o=xml&key=AjvYaTSLr8dsu4eqeDt0OigOZ_xuTkdVMUQCDMc0gcDPmj2m57iWiwasSDZSCoNG")),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Copyright", type text}, {"BrandLogoUri", type text}, {"StatusCode", Int64.Type}, {"StatusDescription", type text}, {"AuthenticationResultCode", type text}, {"TraceId", type text}}),
ResourceSets = #"Changed Type"{0}[ResourceSets],
ResourceSet = ResourceSets{0}[ResourceSet],
#"Changed Type1" = Table.TransformColumnTypes(ResourceSet,{{"EstimatedTotal", Int64.Type}}),
Resources = #"Changed Type1"{0}[Resources],
#"Expanded Location" = Table.ExpandTableColumn(Resources, "Location", {"Name", "Point", "BoundingBox", "EntityType", "Address", "Confidence", "MatchCode", "GeocodePoint"}, {"Location.Name", "Location.Point", "Location.BoundingBox", "Location.EntityType", "Location.Address", "Location.Confidence", "Location.MatchCode", "Location.GeocodePoint"}),
#"Location Point" = #"Expanded Location"{0}[Location.Point],
#"Changed Type2" = Table.TransformColumnTypes(#"Location Point",{{"Latitude", type number}, {"Longitude", type number}})
in
#"Changed Type2"
Use lat long to visualize maps
Use that custom invoke function to get multiple lat long by creating new custom column in table
Later we have to convert embedded table data to column data
To show Country and count legend without mouse over we have created custom legend column
Using the below query
Syntax:
State Count COLUMN = 'Table'[State]&" - "&CALCULATE(SUM('Table'[Count]), ALLEXCEPT('Table', 'Table'[State]))
Once data is ready on the table then we have to drag and drop the proper value on location, legend, values.
Using the answer on this page How to search multiple strings in a string? I managed to write the following query -
let
Source = Csv.Document(File.Contents("P:\DMWORK\all_donations_for_last_10_years.txt"),[Delimiter=" ", Encoding=1252]),
#"Promoted Headers" = Table.PromoteHeaders(Source),
#"Defined Table" = Table.TransformColumnTypes(#"Promoted Headers",
{{"Donation Date", type date}, {"Amount", type number}, {"Company", type text}, {"Extra Codes", type text}}),
Text.ContainsAny = (string as text, list as list) as logical =>
List.AnyTrue(List.Transform(list, (substring) => Text.Contains(string, substring))),
FirstFilter = Table.SelectRows(#"Defined Table", each Text.ContainsAny([Company], {"Assoc","Band","Baseball"})),
SecondFilter = Table.SelectRows(#"Defined Table", each [Extra Codes] = "FUNDRAIS"),
FinalResult = FirstFilter or SecondFilter
in
FinalResult
So what I'm trying to do, is SelectRows that match either the FirstFilter OR the SecondFilter. Yet it's giving me a "Expression.Error: The value isn't a single-character string. Details: Value= " error.
If someone could put me in the right direction to resolve this, I would really appreciate it.
Thanks in advance.
I would simplify this using the secret "or" operator. I'm not being sarcastic - it actually is secret as in totally obscured in their documentation. Try searching for it...
Anyway I would replace the code from FirstFilter down with something like:
Filter = Table.SelectRows(#"Defined Table", each Text.ContainsAny([Company], {"Assoc","Band","Baseball"}) or [Extra Codes] = "FUNDRAIS" ),
in
Filter