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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

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
Super User
Super User

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
Super User
Super User

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
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors