I'm trying to model a data source in power bi, but I'm not getting it.
Could you help me with alternatives so I can create a new column? The data source is in excel and brings the data with subtotal by types (XPTO, XPT, etc). I want to put these types as corresponding values in the new column for your items. I tried via power query and dax, but I could not.
Original Source:
Modifications Needed
Source File
This assumes that you can identify the Subtotal Rows by checking the position of the first space in the first column:
let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Added RowType" = Table.AddColumn(Source, "RowType", each Text.PositionOf([#"Centro financ./item orçamento"]," "), Int64.Type),
#"Added Type" = Table.AddColumn(#"Added RowType", "Type", each if [RowType] = 4 then Text.BetweenDelimiters([#"Centro financ./item orçamento"], " ", " ") else null, type text),
#"Filled Down" = Table.FillDown(#"Added Type",{"Type"}),
#"Filtered Rows" = Table.SelectRows(#"Filled Down", each ([RowType] = 8)),
#"Removed Columns" = Table.RemoveColumns(#"Filtered Rows",{"RowType"}),
#"Reordered Columns" = Table.ReorderColumns(#"Removed Columns",List.Combine({{"Type"}, Table.ColumnNames(Source)}))
in
#"Reordered Columns"
Another solution is to - Include another data source in Power BI, which will look something like this.
Item Type
615x92120 Mat1 XPTA
615x92121 Mat2 XPTA
615x92122 Mat3 XPTU
615x92123 Mat4 XPTU
And then do a Join between your existing table and this table to bring out the Type in your existing table. Once you have done that, you should be able to filter out to blanks or null which will be your delete lines.
Note :- This only works, if you know all the items and corresponding types in advance.
Related
My existing code is but it takes too much of the time
let
Source = Oracle.Database("orcl", [HierarchicalNavigation=true]),
NOVA_SHF = Source{[Schema="NOVA_SHF"]}[Data],
GL_VCHRDETAIL1 = NOVA_SHF{[Name="GL_VCHRDETAIL"]}[Data],
#"Removed Columns" = Table.RemoveColumns(GL_VCHRDETAIL1,{"VD_PST_TAG", "VD_BANK_STNO", "VD_COSTCNTR_CODE", "VD_QUANTITY", "VD_PARTY_CODE"})
in
#"Removed Columns"
Your can specify an SQL Query to SELECT your columns in the Oracle.Database() options: https://learn.microsoft.com/en-us/powerquery-m/oracle-database.
However, you can also specify an SQL in in the Get Data UI:
I would like to know if you can assist me in the following matter:
in PowerQuery I have a column like this:
input
and i would like to Sort the column "CANAL / BU" like this:
I tried to sort the function but sort the entire column not the text.
could you guys please so kind to assist me?
regards,
From your example, it appears you only want to sort the text in a single column.
You can do that by:
Split each text line by the "/" into a List.
Sort the List
Recombine the List using the "/" delimiter.
A line of M Code that will do that:
#"Sort Column" = Table.TransformColumns(#"Previous Step",
{"CANAL/BU", each Text.Combine(List.Sort(Text.Split(_,"/")),"/")})
Of course, you could also do this by adding a custom column and sorting there; but with the Table.TransformColumns method, you don't need the extra column.
Here is code that will reproduce the first few columns of your table, and show the sorting step in situ:
let
Source = Table.FromRecords(
{
[AREA="Channel Marketing",
#"CANAL/BU"="WT/NT/O",
GPID=70181170]
}
),
#"Change Type" = Table.TransformColumnTypes(Source,{{"AREA", type text}, {"CANAL/BU", type text}, {"GPID", Int64.Type}}),
#"Sort Column" = Table.TransformColumns(#"Change Type",
{"CANAL/BU", each Text.Combine(List.Sort(Text.Split(_,"/")),"/")})
in
#"Sort Column"
Output
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 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"```
Need some DAX help with the below data.
I have Columns Uniq ID and Controls.
I want to split the Controls column as shown in New Column.
The string will always start with "AON" and a total of 7 characters (i.e AON0913)
Thanks for help
Here is the Power Query solution. I added comments to understand what each step is doing.
Input Table:
Uniq ID
Controls
RIS123
{AON0913: test 1}, {AON0S18: Safety glasses complying to AS/NZS 1337.1:2010}, {AON0937: Wearing of protective gloves}, {AON0938: First Aid }
RIS345
{AON0913: test 1}, {AON0937: Wearing of protective gloves}, {AON0939: Some SCO's may already have up-to-date vaccinations. }, {AON0938: First Aid }
RIS3223
{AON0S18: Safety glasses complying to AS/NZS 1337.1:2010}, {AON0937: Wearing of protective gloves}, {AON0928: Safety and Compliance uniform Specifications 12-2017 }
RIS0456
{AON0912: test }, {AON0941: controlling test 4321234 }
Power Query M Code:
let
Source = Excel.CurrentWorkbook(){[Name="Table2"]}[Content],
//Add an index so we know the original amount of rows
#"Added Index" = Table.AddIndexColumn(Source, "Index", 0, 1, Int64.Type),
//Add a column to create a list of Split strings after ":", the trailing delimiter. This will create a list with multiple rows.
#"Add Column" = Table.AddColumn(#"Added Index", "Split Colon", each Text.Split([Controls],":")),
//Expand the new rows
#"Expanded Split Colon" = Table.ExpandListColumn(#"Add Column", "Split Colon"),
//Filter out any Row that does not contain "AON0"
#"Filtered Rows" = Table.SelectRows(#"Expanded Split Colon", each Text.Contains([Split Colon], "AON0")),
//Extract the text after "AON0", which will be the three digits. Prefix it with "AON0" to create the full string. This is in case it does not have a leading "{" delimiter.
#"Extracted Text After Delimiter" = Table.TransformColumns(#"Filtered Rows", {{"Split Colon", each "AON0" & Text.AfterDelimiter(_, "AON0"), type text}}),
//Group by the Index that we created earlier. We will group all existing columns together as well as create a new column with a comma delimited string for our Output
#"Grouped Rows" = Table.Group(#"Extracted Text After Delimiter", {"Index"}, {{"All Rows", each _, type table [Uniq ID=nullable text, Controls=nullable text, Index=number, Split Colon=text]}, {"Output", each Text.Combine([Split Colon], ", "), type text}}),
//Expand our groups
#"Expanded All Rows" = Table.ExpandTableColumn(#"Grouped Rows", "All Rows", {"Uniq ID", "Controls"}, {"Uniq ID", "Controls"}),
//Remove any duplicated rows
#"Removed Duplicates" = Table.Distinct(#"Expanded All Rows")
in
#"Removed Duplicates"
Output Table:
You can remove the Index column after you remove the duplicates if it is not needed.
Power BI does not have any native functions in the Power query to perform any RegEx operations (which may be most useful here. Please vote ). What you can do is to use build-in option
Column From Examples; You can here type the desired result in a few rows (where you have the longest example - Max AON occurrence. ) and powerbi should indicate what you want (probably the should use multiple time splitbydelimiter + data.combine function + substring)