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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
NZCraig
Helper I
Helper I

Grouping information from multiple tables

Hi All,

 

I have an problem with querying data that comes from multiple SQL tables and outputs to a format such as Excel, so that I can  identify gaps in data for end users and provide them a tool where they can record any data that needs to be completed.

 

My example tables are as follows:

jobplan table

jpnumdescriptiondurationstatusjobplanid
JP1000JP Description 18Active2101

 

jobtask table

jptaskdescriptionjpnumjobplanid
10JP task 1JP10002101
20JP task 2JP10002101
10JP task 1JP10001999
20JP task 2JP10001999

 

joblabour table

craftquantitylaborhrsjptaskjobplanidjpnum
ELEC28 2101JP1000
EXT-ELEC14202101JP1000
MECH28 2101JP1000
TA412102101JP1000
EXT-MECH14102101JP1000

 

jobmaterial table

itemnumdescriptionquantityjobplanidjpnumjptask
122GASKET12101JP100020
543Nut22101JP100020
67895Bolt12101JP100020
123GASKET11999JP100020

 

 

The desired output needs to be able to show a table that combines all this data, without duplicating all the rows for all the variables and group the common data to make it easier to read. Apologies if this isn't quite the righgt forum for this but I was hoping to do this in power query so that i can adjust the tool dynamically as data is updated. Happy to have a discussion in another forum, or offline from here if there is someone who has a solution, btu this isn't quite where it fits.

 

Thanks in advance, Craig

 

Desired output:

jpnumdescriptiondurationstatusjobplanidjptaskdescriptionjpnumjobplanidcraftquantitylaborhrsjptaskjobplanidjpnumitemnumdescriptionquantityjobplanidjpnumjptask
JP1000JP Description 18Active210110JP task 1JP10002101TA412102101JP1000      
         EXT MECH14102101JP1000      
     20JP task 2JP10002101EXT-ELEC14202101JP1000122GASKET12101JP100020
               543Nut22101JP100020
               67895Bolt12101JP100020
         ELEC28 2101JP1000      
         MECH28 2101JP1000      

 

 

1 ACCEPTED SOLUTION
wdx223_Daniel
Community Champion
Community Champion

wdx223_Daniel_0-1667794545803.png

= List.Accumulate({"JobPlan","JobTask","JobLabour","JobMaterial"},"",(x,y)=>let a=Record.Field(#shared,y),b=List.Intersect({{"jpnum","jobplanid","jptask"},Table.ColumnNames(a),Table.ColumnNames(x)}),c=Table.ColumnNames(a),d=List.Transform(c,each if List.Contains(Table.ColumnNames(x),_) then y&"-"&_ else _),e=Table.NestedJoin(x,b,a,b,"n",JoinKind.FullOuter) in if x="" then a else Table.ExpandTableColumn(e,"n",c,d))

 

View solution in original post

2 REPLIES 2
wdx223_Daniel
Community Champion
Community Champion

wdx223_Daniel_0-1667794545803.png

= List.Accumulate({"JobPlan","JobTask","JobLabour","JobMaterial"},"",(x,y)=>let a=Record.Field(#shared,y),b=List.Intersect({{"jpnum","jobplanid","jptask"},Table.ColumnNames(a),Table.ColumnNames(x)}),c=Table.ColumnNames(a),d=List.Transform(c,each if List.Contains(Table.ColumnNames(x),_) then y&"-"&_ else _),e=Table.NestedJoin(x,b,a,b,"n",JoinKind.FullOuter) in if x="" then a else Table.ExpandTableColumn(e,"n",c,d))

 

Hi Daniel, thanks for having a crack, this isn't quitre what I was after , but i'll keep working through it and see what I can get.

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

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.

Top Solution Authors