Forum Discussion

randyvik's avatar
randyvik
New Member
6 years ago
Solved

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

 

DateTransacted priceTransacted quantitySecurity NameCategorySub-CategoryDate rank
10-01-2017 00:0030100MiraeMutual FundEquity1
10-02-2017 00:0030100MiraeMutual FundEquity2
10-03-2017 00:0030100MiraeMutual FundEquity3
10-04-2017 00:0030100MiraeMutual FundEquity4
10-05-2017 00:0030100MiraeMutual FundEquity5
15-05-2017 00:0030100MiraeMutual FundEquity6
22-05-2017 00:0030100MiraeMutual FundEquity7
12-06-2017 00:0030100MiraeMutual FundEquity8
10-07-2017 00:0030100MiraeMutual FundEquity9
10-08-2017 00:0040200MiraeMutual FundEquity10
17-04-2018 00:0040200HDFC BankStocksStocks1
17-04-2018 00:0040200KEIStocksStocks1
17-04-2018 00:0040200RelianceStocksStocks1
12-03-2019 00:0040200SundaramMutual FundEquity1
20-05-2019 00:0040200Asian paintsStocksStocks1
20-05-2019 00:0040200HDFCStocksStocks1
20-05-2019 00:0040200PidiliteStocksStocks1
23-10-2019 00:0040200Kotak MahindraStocksStocks1
19-12-2019 00:0050300Axis bluechipMutual FundEquity1
23-12-2019 00:0050300HULStocksStocks1
27-02-2020 00:0050300HDFCStocksStocks2
27-02-2020 00:0050300HDFC BankStocksStocks2
02-03-2020 00:0050300HULStocksStocks2
02-03-2020 00:0050300RelianceStocksStocks2
07-04-2020 00:0050300TitanStocksStocks1
09-04-2020 00:0050300TCSStocksStocks1
09-07-2020 00:0050300Axis short termMutual FundDebt1

 

Output for table2

Security namesold quantity
Asian paints0
HDFC0
HUL0
Reliance5
Axis short term0
TCS0
KEI0
Titan0
Sensex0
HDFC Bank0
Kotak Mahindra0
Mirae0
Sundaram0
Pidilite0
Axis bluechip0

 

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

  • Greg_Deckler's avatar
    Greg_Deckler
    6 years ago

    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

    • randyvik's avatar
      randyvik
      New 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 result
       
      However 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?