Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago

Best way to combine these two queries?

I have two different sets of data that I would like to try and combine into one query.  I'm good at transforming a single query, but this sort of merging I don't know how to solve.

 

The main difference between these queries is that Query1 lists work we complete in a Group:Task format, whereas Query2 only lists it as a Task.  Another problem Is that there are multiple different groups and tasks which I believe means there will be a lot of duplicate values where there shouldn't be any.

 

What I'm trying to accomplish is a way to combine these queries so that all of the data shows in one query without any duplication.  I also need to keep all rows in both queries so I'm guessing I need to start with a full outer merge.  What should I do?

 

Query1

 

Query2

2 Replies

  • Try union and summarize

    https://docs.microsoft.com/en-us/dax/union-function-dax

    https://docs.microsoft.com/en-us/dax/summarize-function-dax

     Summary = UNION(
    SUMMARIZE('Table1','Table1'[Customer],'Table1'[created_date],'Table1'[DA Status],"Sales",sum('Table1'[Sales]),"Invoices",count('Table1'[ID]),"Time",DIVIDE(SUM('Table1'[Ship Time]),1),"Stage"," Ship","Gross",sum('Table1'[inv_amount]),"Net",Sum('Table1'[Net Calc Amount]))
    ,SUMMARIZE('Table2','Table2'[Customer],'Table1'[created_date],'Table2'[AA Status],"Sales",sum('Table2'[Sales]),"Invoices",count('Table2'[ID]),"Time",DIVIDE(SUM('Table1'[Order Time]),1),"Stage","Order","Gross",sum('Table1'[inv_amount]),"Net",Sum('Table1'[Net Calc Amount]))
    )

     

     

    Appreciate your Kudos. In case, this is the solution you are looking for, mark it as the Solution. In case it does not help, please provide additional information and mark me with @
    Thanks.

    My Recent Blog - https://community.powerbi.com/t5/Community-Blog/Comparing-Data-Across-Date-Ranges/ba-p/823601

    • Anonymous's avatar
      Anonymous
      Not applicable

      I don't think union would work in this situation.  Doesn't union require the same number of columns in each table?