Forum Discussion
Merge vittual tables
Hello All,
I have 2 virtual table variables in the following DAX code: table1 and table2. But I dont know how to merge virtually
Dummy = var table0 = SELECTCOLUMNS(FILTER('Master table','Master table'[Transacted quantity]<>0),"Date",'Master table'[Date],"Transacted price",'Master table'[Transacted price],"Transacted quantity",'Master table'[Transacted quantity],"Security Name",'Master table'[Security name],"Category",'Master table'[Category],"Sub-Category",'Master table'[Sub-Category])
var table1 = ADDCOLUMNS(table0,"Date rank",RANKX(FILTER(table0,[Security Name]=EARLIER([Security Name])),[Date],,ASC,Dense))
var table2 = SUMMARIZE('Master table','Master table'[Security name],"sold quantity",CALCULATE(SUM('Master table'[Sold quantity])))
return ???
Output for table1
| Date | Transacted price | Transacted quantity | Security Name | Category | Sub-Category | Date rank |
| 10-01-2017 00:00 | 30 | 100 | Mirae | Mutual Fund | Equity | 1 |
| 10-02-2017 00:00 | 30 | 100 | Mirae | Mutual Fund | Equity | 2 |
| 10-03-2017 00:00 | 30 | 100 | Mirae | Mutual Fund | Equity | 3 |
| 10-04-2017 00:00 | 30 | 100 | Mirae | Mutual Fund | Equity | 4 |
| 10-05-2017 00:00 | 30 | 100 | Mirae | Mutual Fund | Equity | 5 |
| 15-05-2017 00:00 | 30 | 100 | Mirae | Mutual Fund | Equity | 6 |
| 22-05-2017 00:00 | 30 | 100 | Mirae | Mutual Fund | Equity | 7 |
| 12-06-2017 00:00 | 30 | 100 | Mirae | Mutual Fund | Equity | 8 |
| 10-07-2017 00:00 | 30 | 100 | Mirae | Mutual Fund | Equity | 9 |
| 10-08-2017 00:00 | 40 | 200 | Mirae | Mutual Fund | Equity | 10 |
| 17-04-2018 00:00 | 40 | 200 | HDFC Bank | Stocks | Stocks | 1 |
| 17-04-2018 00:00 | 40 | 200 | KEI | Stocks | Stocks | 1 |
| 17-04-2018 00:00 | 40 | 200 | Reliance | Stocks | Stocks | 1 |
| 12-03-2019 00:00 | 40 | 200 | Sundaram | Mutual Fund | Equity | 1 |
| 20-05-2019 00:00 | 40 | 200 | Asian paints | Stocks | Stocks | 1 |
| 20-05-2019 00:00 | 40 | 200 | HDFC | Stocks | Stocks | 1 |
| 20-05-2019 00:00 | 40 | 200 | Pidilite | Stocks | Stocks | 1 |
| 23-10-2019 00:00 | 40 | 200 | Kotak Mahindra | Stocks | Stocks | 1 |
| 19-12-2019 00:00 | 50 | 300 | Axis bluechip | Mutual Fund | Equity | 1 |
| 23-12-2019 00:00 | 50 | 300 | HUL | Stocks | Stocks | 1 |
| 27-02-2020 00:00 | 50 | 300 | HDFC | Stocks | Stocks | 2 |
| 27-02-2020 00:00 | 50 | 300 | HDFC Bank | Stocks | Stocks | 2 |
| 02-03-2020 00:00 | 50 | 300 | HUL | Stocks | Stocks | 2 |
| 02-03-2020 00:00 | 50 | 300 | Reliance | Stocks | Stocks | 2 |
| 07-04-2020 00:00 | 50 | 300 | Titan | Stocks | Stocks | 1 |
| 09-04-2020 00:00 | 50 | 300 | TCS | Stocks | Stocks | 1 |
| 09-07-2020 00:00 | 50 | 300 | Axis short term | Mutual Fund | Debt | 1 |
Output for table2
| Security name | sold quantity |
| Asian paints | 0 |
| HDFC | 0 |
| HUL | 0 |
| Reliance | 5 |
| Axis short term | 0 |
| TCS | 0 |
| KEI | 0 |
| Titan | 0 |
| Sensex | 0 |
| HDFC Bank | 0 |
| Kotak Mahindra | 0 |
| Mirae | 0 |
| Sundaram | 0 |
| Pidilite | 0 |
| Axis bluechip | 0 |
In the return statement of DAX, I want a code to merge these tables virtually using their security name column respectively. I cannot create a seperate table for this operation due to other constraints. Also I'm new to Power BI, so it will be of great help to me if anyone of you could share me your solution for this
Thanks
randyvik This however works:
Table 4 = VAR __Table2 = { (1,"A","Black"),(2,"B","White"),(3,"C","Blue")} VAR __Table3 = { (1,"A","One"),(2,"B","Two"),(3,"C","Three")} VAR A = SELECTCOLUMNS(__Table2,"Key",[Value1],"Color",[Value3]) VAR B = SELECTCOLUMNS(__Table3,"Key",[Value1],"Number",[Value3]) RETURN NATURALINNERJOIN(A, B)marcorusso Help! See the Master tables in the attached PBIX. As well as Table 2 and Table 3 and Table 5 (error)
15 Replies
- amitchandak
Super User
randyvik , You have natural inner join and Cross join
Refer this doc: https://www.sqlbi.com/articles/from-sql-to-dax-joining-tables/
- randyvikNew Member
Thanks for your quick response. I tried the following code
Dummy = var table0 = SELECTCOLUMNS(FILTER('Master table','Master table'[Transacted quantity]<>0),"Date",'Master table'[Date],"Transacted price",'Master table'[Transacted price],"Transacted quantity",'Master table'[Transacted quantity],"Security Name",'Master table'[Security name],"Category",'Master table'[Category],"Sub-Category",'Master table'[Sub-Category])var table1 = ADDCOLUMNS(table0,"Date rank",RANKX(FILTER(table0,[Security Name]=EARLIER([Security Name])),[Date],,ASC,Dense))var table2 = SUMMARIZE('Master table','Master table'[Security name],"sold quantity",CALCULATE(SUM('Master table'[Sold quantity])))var result = NATURALLEFTOUTERJOIN(table1,table2)return resultHowever I get an error stating that "No common join columns detected. The join function 'NATURALLEFTOUTERJOIN' requires at-least one common join column". How do I specify the join column in a virtual table?- Greg_Deckler
Community Champion
randyvik Let me mock this up, NATURALINNERJOIN can be maddening sometimes!
- Greg_Deckler
Community Champion
randyvik You would use NATURALINNERJOIN to merge.