I am looking for a DAX function, or any trick with pbi desktop, to do the operation below :
2 tables :
'data' table, with a data column in text format
eg: "Product XXX.YYY"
'ref' table, with 2 columnes, key and label. The keys are usually some substrings of the data fieds.
eg. "Product XXX"; "Label 1"
I need to add to the data table a measure that contains the label matching the first key from the ref table that is a substring of the data
eg : "Product XXX" is a substring of "Product XXX.YYY" => should return "Label 1"
Of course, all values on the data column have a diferent format, so I can not manipulate the data to split "Product XXX" and "YYY" in a static way.
thanks a lot !
Alternative : rather than a dummy substring, if the key could be a full regex pattern to be matched, would be far more interesting ... :)
Without example data it's hard to test if this solution works, but since October 2018 there is a fuzzy matching preview feature.
Steps summary
Enable the fuzzy merge preview feature via File → Options → Preview Features
Go to Edit Queries and click on Merge Queries as New
Select the data table (containing the Product XXX.YYY values) as the source
Select the ref table as the match table
Pick a join type from the drop down
Tick the fuzzy matching checkbox
Try out some fuzzy matching options to see what is suitable
Related
I have a table called "food suppliers" with a column called "sites" that have multiple countries ending in ".com", ".es", ".co.uk".
I want to create a new column that separates these sites into their corresponding country names using the if and search function on power query.
so far in power query custom column I have:
Country = IF (SEARCH ("*.com", foodsuppliers[sites],,0) = 0, IF (SEARCH ("*.es", foodsuppliers[sites],, 0)= 0, "Spain","UK"),"USA")
But I am getting a "token literal expected" under the first = sign in "IF (SEARCH ("*.com", foodsuppliers[sites],,0) = 0"
does any one have ideas why or a better way to run this code on power query/power bi?
thanks.
Nothing in your code seems relevant
There is no SEARCH function, you want to use Text.Contains
You cant write foodsuppliers[sites] or you will be getting the entire column of all rows. You probably want each current row, which you would get with [sites]
This is not excel where you can do =if (xxx,fff,zzz) the format is if x then y else z
I recommend some tutorials
I have a table that looks like this in Power BI:
CourseID Course
1 Math
2 Cooking
3 English
4 Spanish
I want to insert a row at the bottom that looks like this:
-1 null
I looked at the Microsoft Documentation, but it's not very helpful. Any suggestions?
Figured out what I was doing wrong.
Let's say I wanted to insert a row, at top of a table, named Courses.
The M query would look like this
#Insert Row = Table.InsertRows(#PreviousStepName,0,{[CourseID=-1,Course=null]})
Was not able to get it working if the column name had a space in it, but for best practices, you shouldn't have columns with spaces in the name anyway.
Follow below steps to insert a row to the bottom of a table:
Step 1: Go to the edit query window. select the correct table.
Step 2: Go to the APPLIED STEPS window on the right-hand side. double click on Source.
Step 3: Add the data to each column and press ok.
Note that, this will only add a row to the end of the table.
The accepted answer above by OP works great if you want to insert a row at the top of the table, or if you know the index to insert at. In my case I want to append to the end, and the amount of rows is likely to change in future.
I saw the functions to reverse the rows, so you could reverse the rows, insert at 0, then reverse again, but I found another way:
#"Insert Row" = Table.Combine({#"Previous Step Name",
Table.FromRows(
{{null, "None", true, false}},
{"ID", "Name", "Deleted", "IsIntegration"}
)
})
Basically, you create a new table with Table.FromRows, then use Table.Combine to append it
Good evening everyone, I'm having trouble resolving the following question:
I have "Table 1" containing the occurrence records and "Table 2" containing the occurrences.
I need to set up a VIRTUAL TABLE or VIEW TABLE that presents the occurrences and their frequencies as follows:
Tables with Perspective
The most I could do was bring the occurrences with the total number of rows in the table, ie the same amount X for all.
Last try using DaxStudio
You need to create a measure to show the numbers in the report.
But first, it is recommended to transform the table into a form like below, where each occurrence appears in each row. This has a lot of advantage to make the DAX measure simpler, more accurate, and run faster.
This can be easily achieved using Power Query Editor. The required steps are,
Select the comma delimited occurrences column.
In Transform tab, click Split Column and choose By Delimiter.
Make sure Comma and split at Each occurrence of the delimiter is selected by default.
In Advanced options, select split into Rows, then click OK.
Then you can define a measure to count the number of occurrences, which is as simple as below.
Count = COUNTROWS ( Tabela1 )
Now, in the report area, you can use the measure to obtain the desired output.
I have recreated your tables and here is the DAX for Table3 (perspectiva):
Table3 =
VAR uniqueOccurences = DISTINCT(Table2[Occurence])
RETURN
ADDCOLUMNS(uniqueOccurences,
"count",
VAR currentOccurence = [Occurence]
RETURN
CALCULATE(COUNTA(Tabel1[ID]),
FILTER(Tabel1, CONTAINSSTRING(Tabel1[Occurences], currentOccurence) = TRUE()))
)
This returns the following table:
Please mark this as the solution if this answered your question :)
Requested behaviour:
I would like to create a search form in Google Sheets to query a table that I use as a database.
The user should be able to query the table by multiple searches
categories which the user can type into a cell of the sheet.
If the user does not type in a search string, then all items
should be displayed.
Also, the user should be able to choose between an
"including OR" and an "excluding AND" search.
The original table is on a different sheet than the search form. The final searchform should have more than 10 searchable categories.
Current State
Since the original table is in a different sheet than the search form, my idea has been to import the table by a dynamic query() function.
I created two input search input fields and a field where the user can switch between "OR" and "AND". I also created a query function that connects these 3 search terms.
The change between "OR" and "AND" search works (with the first approach).
First approach:
=QUERY('Geschäftsvorfälle'!A2:AG1000, "select * WHERE A="&B4&" "&D1&" B='"&B5&"'")
Second approach:
=QUERY('Geschäftsvorfälle'!A2:AG1000, "select * " &if(B5="Alle",, "WHERE B='"&B5&"'") &if(B4="",, "WHERE A="&B4&""))
Issue
The first approach works with the "OR" search but gives an empty sheet back if I use multiple search terms. It also throws a "VALUE" error if leave one search term blank. The second approach throws a "VALUE" error if I use multiple search terms even there should be matching rows.
Is there a way to make this kind of a searchform work in Google Sheets? If yes is it possible to do it with query() and how do I do it? Could you provide some example screenshots or code?
Screenshots
The searchform:
The combining query:
try:
=QUERY('Geschäftsvorfälle'!A2:AG,
"where "&TEXTJOIN(" "&D1&" ", 1,
IF(B4<>"", " A="&B4, ),
IF(B5<>"", " B='"&B5&"'", ),
IF(B6<>"", " lower(F) contains '"&LOWER(B6)&"'", )), 1)
I have imported a JSON file into PowerBI and it contains a column in which the values are of type "List". I am looking to expand that column into multiple columns.
Specifically, the data contains a Sprint Name, the start date and the end date of the sprint, along with some other values associated with each sprint.
Trying to use "Expand to new rows" duplicates each sprint instance, creating a table that looks like this, duplicating each sprint instance multiple times for each associated value:
Sprint Name Value
JAN(S1Dev) 2019-01-01
JAN(S1Dev) 2019-01-13
JAN(S1Dev) {attribute}
JAN(S1Dev) {attribute}
JAN(S2Dev) 2019-01-14
JAN(S2Dev) 2019-01-31
JAN(S2Dev) {attribute}
JAN(S2Dev) {attribute}
FEB(S1Test) 2019-02-01
FEB(S1Test) 2019-02-15
... ...
I would like to do something similar to the "expand" feature, which instead creates a new column with each attribute rather than a new row. This is currently vastly increasing the size of my table for no reason, while also making the data practically un-useable. Any help would be appreciated, cheers!
I have found a very simple solution to this, but as it took me some time to figure it out I will answer my own question instead of deleting it to help others in the future...
Upon importing the JSON data into PowerBI first select "Convert to Table" to view the data as a table with editable properties.
Next, click the arrows pointing away from each other at the top of the column of Lists, and select "Extract Values".
Select a delimiter to use for concatenating values, I am choosing a comma since I know that the data contained within the list does not have any commas in it. If your data contains commas within it, choose something else. Similarly, if your data contains one of the delimiters, do not choose that as the delimiter.
It should now display a comma-separated list where it previously displayed "List" in orange text.
Now, right-click on the column and select "Split Column" then choose "By Delimiter"
Select the delimiter that you previously chose, and under "split at" select "Each occurrence of the delimiter" then click OK.
Your column should now be split into multiple columns based on the list!