Ok, so I'm trying to take two rows and subtract them to make another column with that difference. I know that there is a Question like this already but it need more help. here is the code that I think would work.
=Table.AddColumn(#"YourLastStep", "Diff",
each
(try DateTime.From(#"YourLastStep"[Time]{[ID]-2})
otherwise DateTime.From([Time])) - [Time]
)
But I don't understand "=Table.AddColumn(#"YourLastStep", "Diff",
each." what does "YourLastStep" mean please help.
Thank you,
If I take the following
let
Source = {1..10},
#"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
#"Changed Type" = Table.TransformColumnTypes(#"Converted to Table",{{"Column1", Int64.Type}})
in
#"Changed Type"
In #"Changed Type" step, YourLastStep is #"Converted to Table"
In #"Converted to Table" step, YourLastStep is Source
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"
my data number came in text form, for example: 4.1M 1.22B 3K
Is there a way to turn them back into numbers like 4100000 for 4.1M
Thanks in advance
If you are using card visualization you have feature to change count for thousands, millions etc. It depend on visualization.
You can follow the following steps:
Select the visual where you want to change this notation
Click on the paint roller in the Visualisations pane
You have already activated labels, expand this part
Here you can choose how to show values, select whatever you want
Keep in mind however that big numbers are hard to read and easy to read wrong. It is worth considering to keep them as 4.1M and 1.22B since it keeps them nice and compact. This is especially the case if you use visualisations that grow over time, where overlap might occur easily if you have written-out numbers.
Also, refer to the following documentation for explanation on the Microsoft website:
https://learn.microsoft.com/en-us/power-bi/visuals/power-bi-visualization-customize-title-background-and-legend
Here is an example of how to clean data in Power Query. It is a bit cumbersome, and personally I would contact whoever is responsible for my data source and ask if I could get data in a better format.
The idea is to first figure out what type of multiplier you want to apply to each row, then clean out the "foreign" symbols in the Sample Value column - this is generated using a nifty trick with Character.FromNumber, see link: https://www.excelguru.ca/blog/2015/11/19/keep-only-numbers-in-power-query/ )after that it is simply to convert the original column to a number (might have to remove #"Replaced Value" step depending on your locale) and create a final column that multiplies the number with the multiplier.
You can paste the below into a blank query to see for yourself:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMtEz9FWK1YlWMtQzMnICs4y9IQLGSrGxAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Sample Values" = _t]),
#"Added Conditional Column" = Table.AddColumn(Source, "Custom", each if Text.Contains([Sample Values], "B") then Number.Power(10,9) else if Text.Contains([Sample Values], "M") then Number.Power(10,6) else if Text.Contains([Sample Values], "K") then Number.Power(10,3) else 1),
CharsToRemove = List.Transform({33..45,47,58..126}, each Character.FromNumber(_)),
#"Added Custom" = Table.AddColumn(#"Added Conditional Column", "Result", each Text.Remove([Sample Values],CharsToRemove)),
#"Replaced Value" = Table.ReplaceValue(#"Added Custom",".",",",Replacer.ReplaceText,{"Result"}),
#"Changed Type" = Table.TransformColumnTypes(#"Replaced Value",{{"Result", type number}}),
#"Added Custom1" = Table.AddColumn(#"Changed Type", "Result Value", each [Result]*[Custom], type number),
#"Removed Other Columns" = Table.SelectColumns(#"Added Custom1",{"Result Value"})
in
#"Removed Other Columns"
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))"
Still stumbling my way through Power BI.
I have added a new column in just a few of the files in the folder that I had already pulled in and combined but this column is not appearing once refreshed. Despite the endless research, I am at a loss as to how to fix this in advanced editor.
Your assistance would be greatly appreciated.
Code below:
Source = Folder.Files("C:\Users\Sarah\OneDrive\FEEDLOT\APS Files\Original Files"),
#"Filtered Hidden Files1" = Table.SelectRows(Source, each [Attributes]?[Hidden]? <> true),
#"Invoke Custom Function1" = Table.AddColumn(#"Filtered Hidden Files1", "Transform File", each #"Transform File"([Content])),
#"Renamed Columns1" = Table.RenameColumns(#"Invoke Custom Function1", {"Name", "Source.Name"}),
#"Removed Other Columns1" = Table.SelectColumns(#"Renamed Columns1", {"Source.Name", "Transform File"}),
#"Removed Errors1" = Table.RemoveRowsWithErrors(#"Removed Other Columns1", {"Transform File"}),
#"Expanded Table Column1" = Table.ExpandTableColumn(#"Removed Errors1", "Transform File", Table.ColumnNames(#"Transform File"(#"Sample File"))),
#"Changed Type" = Table.TransformColumnTypes(#"Expanded Table Column1",{{"Source.Name", type text}, {"Tag Number", type text}, {"Electronic ID", type text}, {"NLIS", type any}, {"Date", type datetime}, {"Live Weight (kg)", type number}, {"Draft", type any}, {"Condition Score", type any}, {"Notes", type any}}),
#"Renamed Columns" = Table.RenameColumns(#"Changed Type",{{"Source.Name", "APS Source File Name"}, {"Tag Number", "Visual ID"}}),
#"Split Column by Delimiter" = Table.SplitColumn(#"Renamed Columns", "APS Source File Name", Splitter.SplitTextByEachDelimiter({"-"}, QuoteStyle.Csv, true), {"APS Source File Name.1", "APS Source File Name.2"}),
#"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"APS Source File Name.1", type text}, {"APS Source File Name.2", type text}}),
#"Removed Columns" = Table.RemoveColumns(#"Changed Type1",{"APS Source File Name.2"}),
#"Renamed Columns2" = Table.RenameColumns(#"Removed Columns",{{"APS Source File Name.1", "APS Source File Name"}})
First of all, check twice you are reading the correct file and backup the current script. Then, I would try two approaches:
Delete the steps until you find the one that causes the problem. Then, fix the step causing the issue and check if at the end of the pipeline the columns appear.
If this does not solve the issue, I would go with the second approach:
Create a new PBIX, and one-by-one re-implement all the steps until you find the one causing the new columns to disappear.
Don't try to fix this in Advanced Editor alone. Instead, step through the code and inspect the result after each step. That will show you where the problem is.
Without seeing your data it is not possible to tell you where in your code you need to make changes, but you will be able to see that if you step through the actions one by one.
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.