Use DAX to get data between 2 tables - powerbi

I have table 'tblA' with only 1 column named 'Value'
Value
1
2
The second table 'tblB' with several columns
Col1 Col2
Test A
Dump B
How can I have a join between them so that I will have new table with result like this (each value in tblA will fill in to all rows in tblB):
Col1 Col2 Value
Test A 1
Dump B 1
Test A 2
Dump B 2
I also tried to use for loop to get one-by-one value in tblA. But it seems that DAX didn't support loop.
Please advise.

Use expression for a calculated table
tblC = CROSSJOIN ( tblA, tblB )

Related

How to create dynamic ranking excluding one column the table in Power BI?

I have a summary table as input to Power BI, sample shown below:
Col1
Col2
Col3
Profit
A
P
E
546
A
Q
F
456
A
P
F
343
A
Q
E
897
I have created a report in Power BI using dynamic ranking. I have used following expression for rank measure:
Rank = RANKX(ALLSELECTED(Table), Calculate(sum(Table[Profit])), ,DESC, Dense)
But when filters are applied, above rank is re-generated using all the 3 categorical columns into consideration. But I would like to re-generate ranking based on only 2 columns (suppose col1 and col2 only) when filters are applied and col3 column is only used for filtering purpose. How can I achieve it?

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:

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]))

How to create new column in power bi using given string match condition in first column and get value from another column, make new column?

My table is as follow
Col1 Col2
11_A 9
12_B 8
13_C 7
14_A 6
15_A 4
The table we need after the query
Col1 Col2 Col3
11_A 0 9
12_B 8 0
13_C 7 0
14_A 0 6
15_A 0 4
My query is
Col3 =
LEFT( 'Table'[Col2],
SEARCH("A", 'Table'[Col1], 0,
LEN('Table'[Col1])
)
)
Go to the query designer Add Column > Custom Column and use the following expression:
Update
You need two expressions (two new columns) for this:
One is:
'Your Column3
=if Text.Contains([Col1], "A") = true then [Col2] else 0
And the second:
'Your Column2
=if Text.Contains([Col1], "A") = false then [Col2] else 0
There are many ways to solve this,
Another easy way I like to do this with no-coding is to use Conditional Columns:
In PBI select Power Query Editor
Select your table on the edge of the screen
Select Add Column tab
Select Conditional Columns...
Name your column
Enter your condition as in the picture
You can add several conditions if you like
Don't forget to format your column to numeric if needed.
see picture
Adding columns using Conditional Column