Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

Reply
OlegV
Helper III
Helper III

Combine two tables

Hello,

I have created two calculated tables. 

But I need to have only one.

 

Could you please tell me how can I combine them in one query?

 

I tried to use summarize, but it cannot see fileds of the variable.

 

Here are the codes:

table1 =

VAR SelectedSalesOrders =

    SELECTCOLUMNS(

        FILTER(

            'SalesOrders',

            'SalesOrders'[Date ordered] >= DATE(YEAR(TODAY()), 1, 1) &&

            'SalesOrders'[SO Line type] <> "6"

        ),

        "Company&SalesOrder&StockCode", 'SalesOrders'[Company] & 'SalesOrders'[Sales Order] & 'SalesOrders'[Stock Code]

    )

 

VAR WIPjobsColumns =

    SELECTCOLUMNS(

        WIPJobs,

        "Jobs", 'WIPJobs'[Job],

        "Company&SalesOrder&StockCode", 'WIPJobs'[Company] & 'WIPJobs'[Sales Order] & 'WIPJobs'[Stock Code]

    )

 

VAR LeftJoin1 =

    NATURALLEFTOUTERJOIN(SelectedSalesOrders, WIPjobsColumns)

 

RETURN

  distinct ( LeftJoin1)

 

 

 


Table 2 =

SUMMARIZE(

    'table1',

    'table1'[Jobs]

)

 

 

1 ACCEPTED SOLUTION
AmiraBedh
Super User
Super User

 

 

 

VAR CombinedTable =
VAR SelectedSalesOrders =
    SELECTCOLUMNS(
        FILTER(
            'SalesOrders',
            'SalesOrders'[Date ordered] >= DATE(YEAR(TODAY()), 1, 1) &&
            'SalesOrders'[SO Line type] <> "6"
        ),
        "Company&SalesOrder&StockCode", 'SalesOrders'[Company] & 'SalesOrders'[Sales Order] & 'SalesOrders'[Stock Code]
    )

VAR WIPjobsColumns =
    SELECTCOLUMNS(
        WIPJobs,
        "Jobs", 'WIPJobs'[Job],
        "Company&SalesOrder&StockCode", 'WIPJobs'[Company] & 'WIPJobs'[Sales Order] & 'WIPJobs'[Stock Code]
    )

VAR LeftJoin1 =
    NATURALLEFTOUTERJOIN(SelectedSalesOrders, WIPjobsColumns)

RETURN
    DISTINCT ( SELECTCOLUMNS(LeftJoin1, "Jobs", [Jobs]) )

// Or if you want to summarize based on Jobs and perform aggregation, you can do something like this:
// SUMMARIZE(LeftJoin1, [Jobs], "SomeAggregatedValue", SUM('WIPJobs'[SomeColumnForAggregation]))

RETURN
  CombinedTable

You need to perform the join and selection operations as you did in table1 and then immediately summarize the resulting table in the same query. However, since SUMMARIZE is typically used for grouping data and performing aggregations, and you seem to want to list Jobs uniquely, you might consider using DISTINCT if you're just listing distinct Jobs values. If you need additional aggregation, you can include those in the SUMMARIZE. 


Proud to be a Power BI Super User !

Microsoft Community : https://docs.microsoft.com/en-us/users/AmiraBedhiafi
Linkedin : https://www.linkedin.com/in/amira-bedhiafi/
StackOverflow : https://stackoverflow.com/users/9517769/amira-bedhiafi
C-Sharp Corner : https://www.c-sharpcorner.com/members/amira-bedhiafi
Power BI Community :https://community.powerbi.com/t5/user/viewprofilepage/user-id/332696

View solution in original post

3 REPLIES 3
AmiraBedh
Super User
Super User

 

 

 

VAR CombinedTable =
VAR SelectedSalesOrders =
    SELECTCOLUMNS(
        FILTER(
            'SalesOrders',
            'SalesOrders'[Date ordered] >= DATE(YEAR(TODAY()), 1, 1) &&
            'SalesOrders'[SO Line type] <> "6"
        ),
        "Company&SalesOrder&StockCode", 'SalesOrders'[Company] & 'SalesOrders'[Sales Order] & 'SalesOrders'[Stock Code]
    )

VAR WIPjobsColumns =
    SELECTCOLUMNS(
        WIPJobs,
        "Jobs", 'WIPJobs'[Job],
        "Company&SalesOrder&StockCode", 'WIPJobs'[Company] & 'WIPJobs'[Sales Order] & 'WIPJobs'[Stock Code]
    )

VAR LeftJoin1 =
    NATURALLEFTOUTERJOIN(SelectedSalesOrders, WIPjobsColumns)

RETURN
    DISTINCT ( SELECTCOLUMNS(LeftJoin1, "Jobs", [Jobs]) )

// Or if you want to summarize based on Jobs and perform aggregation, you can do something like this:
// SUMMARIZE(LeftJoin1, [Jobs], "SomeAggregatedValue", SUM('WIPJobs'[SomeColumnForAggregation]))

RETURN
  CombinedTable

You need to perform the join and selection operations as you did in table1 and then immediately summarize the resulting table in the same query. However, since SUMMARIZE is typically used for grouping data and performing aggregations, and you seem to want to list Jobs uniquely, you might consider using DISTINCT if you're just listing distinct Jobs values. If you need additional aggregation, you can include those in the SUMMARIZE. 


Proud to be a Power BI Super User !

Microsoft Community : https://docs.microsoft.com/en-us/users/AmiraBedhiafi
Linkedin : https://www.linkedin.com/in/amira-bedhiafi/
StackOverflow : https://stackoverflow.com/users/9517769/amira-bedhiafi
C-Sharp Corner : https://www.c-sharpcorner.com/members/amira-bedhiafi
Power BI Community :https://community.powerbi.com/t5/user/viewprofilepage/user-id/332696

Thank you very much. It has worked.

I understood my mistake now.

Glad to help 🙂


Proud to be a Power BI Super User !

Microsoft Community : https://docs.microsoft.com/en-us/users/AmiraBedhiafi
Linkedin : https://www.linkedin.com/in/amira-bedhiafi/
StackOverflow : https://stackoverflow.com/users/9517769/amira-bedhiafi
C-Sharp Corner : https://www.c-sharpcorner.com/members/amira-bedhiafi
Power BI Community :https://community.powerbi.com/t5/user/viewprofilepage/user-id/332696

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

FabCon and SQLCon Highlights Carousel

FabCon &SQLCon Highlights

Experience the highlights from FabCon & SQLCon, available live and on-demand starting April 14th.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.