Compare a value from two column and get matching value from another table Power BI - powerbi

I am fairly new to powerbi and I need your help in one task on which I am stuck on.
Basically I have two tables and I need to compare the value from table one with a row of table 2 and return the output.
Table 1
I need to compare values in column a & b and get a match from table 2.
For example if row 1 has BY Green & BS HIGH then I need to check this value from matrix table below and return the output in column value as either 0 or 1.
Table 2
As you can see the Table 2 first row has value BY Green and BS low has a value '0'

Try this...
Index() returns a value from the matrix (in purple) based upon the intersections of the two match()'s. The first is the Vertical match in from the Table1:Col A; the second is the Horizontal match from table1:Col B. The value found at that intersection is returned.
... My apologies ... just saw this was a BI request... no worries...
First, Need fixup table2 as a lookup file:
First, click a cell in table 2 (don't edit), then Data menu >frm table/range, will bring up the Power Query window. Select columns B (not A) through Col F), then in the PQ Transform menu > Unpivot to create the new lookup table. this can either be saved as a new table or be used by reference.
Next, open and merge Table 1 PQ_Table 2 (Be sure to select BOTH Columns in BOTH Tables, in the same order). Then, expand the table tab following the merge expand the table tab. I only selected the value to return but you can return all the values to verify, then delete the unneeded columns.
Hope this helps...
Good Luck.

Related

make all values of mutiple columns in one column Power Bi

I want to get this result (in the picture) using this code but it doesn't work , any suggestions to have all the values of all columns in one column and keep occurrences.
AllZipCode=UNION(SUMMARIZE('Table','Table'[ZipCode1]),
SUMMARIZE('Table','Table'[ZipCode2]),
SUMMARIZE('Table','Table'[ZipCode3]))
It is unlikely to combine all the column and return it in the existing table, else it will return error, by create a new table to join all the column referring to the table, you can achieve the expected output:
Table = UNION(SELECTCOLUMNS(Sheet1,"col1",Sheet1[Zip1]),
SELECTCOLUMNS(Sheet1,"col2",Sheet1[Zip2]),
SELECTCOLUMNS(Sheet1,"col3",Sheet1[Zip3]))
Original table :
Union table:

Power BI: shifting a column one row above

I have a case that I want find the duration for each "state_id", by subtracting its change_time from the time just below it.
So I want to generate a new column that duplicates the column "change_time" and shifting all values one row up, so the change_time #2(in red) would come next to change_time #3(in red).
Is there a way to shift that column one row up?
After a lot of thinking and researching. I have solved it with the following steps:
Sort you columns of interest from A-Z (in my case sort: ticket_id, then history_type_id, then stat_id)
make a first new index column starting from 0 using "Index column from 0".
make a second new index column starting from 1 using "Index column from 1".
merge your query with itself using "merge query" based in the two new indices.
expand the merged query for the date column only.
Now you will have a new date column, duplicated from the old one with a shift of one row.
2)

Power BI : How to count occurrence of value from source table?

I have my data source something like below.
I need to show output in the report as below.
I tried using the unpivot column and getting something like this, how to count the occurrence value of each Business value.
Plot following mesure against Value column (from your unpivot table):
Business Occurance = COUNTROWS('your unpivot table')
We have to remove the Attribute column as the next step to Unpivot. Then my table should be looks like this.
Now create a new table with following Dax function, let's say the current table as Business Data (Your Unpivot table)
Occurrence Table = DISTINCT('Business Data')
Now end result table should look like this,
You can make use of this table for your table visual in the report.
Note: You can add n-number of rows and column into your source table and this logic will do magic to get the correct result.
I have marked two places first marked place you have to add Value column then click second marked place one dropdown value is open click count menu

M query - Edit the value of cell H2 in a table

Having imported an excel sheet into power query, I need to tidy it up by changing the value of a particular cell.
At the moment that cell has a null value, but there are other null values in the same column that I do not want to change. – So I cannot replace all of the null values in that column with another value.
I also cannot correct that particular cell in the source excel file (there are hundreds of them, which were created before I arrived).
I basically need some syntax for example that sets the value of cell H2 to “Jeep”, but not to change any other cells.
Very grateful for any insight.
One way would be:
In the Power Query Editor:
Add an index column starting from 1 (tab Add Column)
Add a Conditional column: If [Index] = 2 then Jeep else [H] (tab Add Column)
Delete Index column and [H] Column
Rename Custom column to [H].

Sort column with repeated values by another column

In Power BI Desktop, I'm trying to order the following column with repeated values by an ID column (contains primary key).
This returns the error: "There can't be more than one value in "Nível2"...."
In this other post it seems the suggestion is to concatenate the values of the column so they don't get duplicate.
But I want them to be repeated so they can aggregate values in visuals.
So, what's the workaround for this situation?
Thanks in advance for helping!
The issue is that your sort column (i.e. your ID column) contains multiple values for each value in the column you are trying to sort (i.e. your Nivel2 column).
You need to ensure that your sort column contains only one distinct value for each value in the column you are trying to sort.
One way to achieve this would be to create a new (calculated) sort column based on your ID column. It could be defined like this:
SortColumn:=CALCULATE(MAX('YourTable'[ID]),ALLEXCEPT('YourTable','YourTable'[Nivel2]))
Here is an example of how the SortColumn would behave:
Id Nivel2 SortColumn
1 Caixa 4
2 Caixa 4
3 Caixa 4
4 Caixa 4
5 Depósitos à ordem 7
6 Depósitos à ordem 7
7 Depósitos à ordem 7
You can now sort Nivel2 by SortColumn.
EDIT - The implementation of the SortColumn should be done in the data source
There seems to be a limitation in PowerBI where it checks the implementation of the sort column rather than the data in the sort column. Therefore the above solution does not work, even though the data in the sort column is perfectly valid. The above solution will throw this error when you attempt to sort [Nivel2] by SortColumn:
This column can't be sorted by a column that is already sorted, directly or indirectly, by this column.
The implementation of the SortColumn should be moved to the data source instead. I.e. if your data source is an Excel sheet, then the SortColumn should be created inside the Excel sheet.
The above answer does explain the issue and the resolvation correctly. The only change is that the SortColumn must be implemented outside of the tabular model (PowerBI) to ensure that PowerBI does not know about the dependency between the SortColumn and the [Nivel2] column.
In my case, I calculate the levels from a parent-child hierarchy
Path = Path([id],[father])
For each level:
Level1 = LOOKUPVALUE([Name],[id], PathItem([Path],1))
Level2 = LOOKUPVALUE([Name],[id], PathItem([Path],2))
.....
Then I created a new column for each level to sort the column Level:
SortL1 = LOOKUPVALUE([nID],[id], PathItem([Path],1))
SortL2 = LOOKUPVALUE([nID],[id], PathItem([Path],2))
.....
id and nID is the same numeric variable but "id" in string format because Path do not support numeric values.