Forum Discussion
Merge Queries - Add column from query 2 or query 3 based on col;umn value in query 1
I need to add three columns from query 2 or query 3 to my query 1 based on the value in a column in query 1
So for example say my query 1 has a column, with the values A or B within it
I need to add three columns to query 1 and take the values for these columns from query 2 if my column has a value A or from query 3 if my column has value B
Can i do this in one go?
At the moment I am using merge queries on my column twice which adds six columns. I then created three more columns with logic to grab the figures from the first or second three columns. Then delete the excess. Not efficient but working
2 Replies
- amitchandakSuper User
You can use a union and Summarize. You can use static values for columns not having value in one query. 0 in sort column query 2.
DATATABLE you can use to add any static values.
Balance Sheet = union(SUMMARIZE(Sales,Sales[Brand],"Col1",sum(Sales[Sales]),"Col2",sum(Sales[COGS]),"sort",COUNTROWS(Sales)),SUMMARIZE(Sales,Sales[Brand],"Col1",sum(Sales[Sales]),"Col2",sum(Sales[COGS]),"sort",0),DATATABLE("Area",STRING,"Col1",DOUBLE,"Value",DOUBLE,"Clo2",DOUBLE ,{ {" ",0.0,0.0,10000} } ) )You can use it as a table, group data further.
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 - v-chuncz-msftCommunity Support