Matching columns from 2 tables - powerbi

I have 2 data in Power BI- Table and Table 2.
I would like to know how can I achieve Table 3 from Table 1 and Table 2.
Thanks !
Tried using text.contains to search, but its taking too long.

Add 2 calculated colmuns to your Table:
City = RELATED('Table 2'[City])
Country =
IF(
'Table'[City] = BLANK(),
'Table'[Location],
RELATED('Table 2'[Country])
)
The resulting Table will look like this:

Related

Use DAX in powerbi to create a measure to calcul ate using two tables A and B (matching by id) applying a filter on table B

I have 2 tables in powerbi
Table A
ID
Name
1
Zelu
2
Bezeu
3
Aquino
Table B
ID_A
Class
1
A
1
A
1
B
2
A
And a wish to calculate count of names with class A
like
Zelu - 2
Bezeu - 1
Aquino - 0
There is away to use a DAX function to execute this job?
Thanks a lot!!!
Saulo
I tryed to use calculate function but i don´t know how to link tow tables.
You need to first establish a relationship between your tables that goes from ID in Table A to ID_A in Table B:
Then you simply add a measure:
Count =
COUNTROWS ( 'Table B' ) + 0
Which you can use in a matrix visualization together with 'Table A'[Name] and 'Table B'[Class] to get your desired result:

Power BI - SUM IFF Across two (not related) tables

I need help about Power bi.
PROBLEM:
I have two tables (most of the fields in the tables are the same, but tables are not equal) , I have Unit name in both tables, and I need a table (output) that contains each Unit and the COUNT of the unit (how many time that unit is in table 1 and in table 2) based on 2 conditions:
I have to count only units that have status not equal to "rejected".
I have to count only units that have the Department_Name = "TX"
I used this DAX measure (but it didn't work):
Measure = calculate(
COUNT(Table 1[Unit_Name]) + COUNT(Table 2[Unit_Name]),
Table 1[Status] <> "rejected",
Table 2[Status] <> "rejected",
Table 1[Department_Name] <> "TX",
Table 2[Department_Name] <> "TX")
The purpose is to use the measure in a PowerBI chart and insert on the X axis the measure, on the Y axis the unit_name (I don't know if I have to use unit_name by Table 1 or unit_name by table 2).
I also tried to create a connection between tables using unit_name as primary key.
IMAGE
there are many ways to do that but the quickest and easiest way is to merge the two tables in to one like
go into the power Query editor , and merge the two tables into one using Power Query Script
for details on how to merge the two tbale data set in power Query see the below link :
https://www.c-sharpcorner.com/article/merge-two-tables-in-power-bi/
video tutorial :
https://www.youtube.com/watch?v=cX62HBIZdPA
after doing this your table will be one instead of 2 tables and you can easily perform the count on single column "Department Name" for the Unit occurance.
Using DAX, It is a 2 step process:
First Create a new table with this DAX Code:
FullJoin = UNION(Table1,Table2)
Your Table will look like this:
Then Create a measure with DAX Code like this:
Solution = CALCULATE(
COUNTX(FullJoin,[Unit_Name]),
FullJoin[Status] <> "rejected",
FullJoin[Department_Name] = "TX"
)
Now If we test it on a visual,

POWERBI: How to make a new table from the intersection of the values ​of a repeated column in two tables

I have two tables with the same columns and I want to make a union between them, in such a way that I get a table in which I only have the products_id that match between them.
Simplifying my case and omitting the rest of the columns (customer_id, order_date_id, etc.):
TABLE 1:
product_id
1
2
2
2
TABLE 2:
product_id
1
1
3
4
The result I want to achieve in this case would be the following:
TOTAL TABLE:
product_id
1
1
1
2
2
2
PS: Note that there are more columns, so the UNION() function by itself is not enough.
Thanks a lot!!
Please test this if I understand correctly:
CombinationTable =
VAR Tbl_1 = Table1
VAR Tbl_2 =
INTERSECT ( Table2, Table1 )
VAR Combination =
UNION ( Tbl_1, Tbl_2 )
RETURN
Combination

How to dynamically add rows to column in power bi/power query

I'm facing a challenge in power bi where I need to join Table 1 & Table 2 but the catch is Table 2 needs to be pivoted before joining.
Input:
Table 1
Table 2
Expected Output:
How to build the output table when the Table 2 rows will be increasing daily
Your desired result needs a combination of Unpivot, Merge and Pivot steps.
You can follow the following steps:
Convert the Date column to Text type.
Unpivot columns Sales in KG & Sales in Amount from Table 2 - it will create 2 columns called Attribute & Value
Merge columns Date & Attribute to create a new column (lets call it columnHeaders) - this will be in the format - 1/3/22 Sales in KG, 1/3/22 Sales in Amount ...
Merge Table 1 into Table 2 and expand the Product Name column
Now you will have 4 columns - Product Code, columnHeaders, Value, & Product Name
Pivot columnHeader using the Value column for values
You should have your desired result.
I dont know why you try to unpivot your table. Just use a Matrix visualization:
Model relationship:
Imput data + output:
sum of kg = CALCULATE(sum(Table2[Sales in kg]))

Create new Column in Power Bi with RegEx

I'm relatively new to Power BI and want to generate a new one based on a column. The contents of the new column should be based on the first value of another column. For example:
ColumnA NewColumn
1123 Argentinia
5644 Brazil
5555 Brazil
3334 Denmark
1124 Argentinia
As you can see, the first value of the number decides which country will be added to the new column.
In SQL I know that I can use something like this:
`select * from table where column LIKE '%[2]`%'
and so on but is this possible with Power BI? Thanks a lot.
Edit:
My additional list looks like this:
ID Country
1 Argentina
2 Swiss
3 Denmark
4 Norway
5 Brazil
and so on...
I thougt I could use somethin like this:
NewColumn = IF('table'[ColumnA] = "%[1]`%"
THEN "Argentinia"
ELSE if IF('table'[ColumnA] = "%[2]`%
THEN Swiss
ELSE "No Country")
Add your Number / Country List to a new table. Let's assume you call it Countries.
Now you can add a column to your original table (let's assume you've called that one Fact Table), using something like:
Country =
LOOKUPVALUE (
Countries[Country],
Countries[ID],
VALUE ( LEFT ( 'Fact Table'[ColumnA], 1 ) )
)
See https://pwrbi.com/so_56391689/ for worked example.
Okay, I've now also found a solution:
NewColumn = SWITCH(TRUE();
LEFT(table[ColumnA]; 1) in {"1"}; "Argentina";
LEFT(table[ColumnA]; 1) in {"2"}; "Swiss";
LEFT(table[ColumnA]; 1) in {"3"}; "Denmark";
LEFT(table[ColumnA]; 1) in {"4"}; "Norway";
LEFT(table[ColumnA]; 1) in {"5"}; "Brazil"
)
Works very well :)