Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
I have a table with dates and production values as following: .
I want to make to merge the columns and make a new table with 3 columns: Date, Production and Country. Currently I managed to merge the date and production columns under two but am struggling to create a separate 3rd column where I could assign data from each column to a specific country.
The code I have currently written:
newTable = VAR tbl1 = SELECTCOLUMNS(Table2, "Date", [Month], "Production", [Crude Oil Production, Algeria]) VAR tbl2 = SELECTCOLUMNS(Table2, "Date", [Month], "Production", [Crude Oil Production, Angola]) RETURN UNION (tbl1, tbl2)
newTable = VAR tbl1 = SELECTCOLUMNS(Table2, "Date", [Month], "Production", [Crude Oil Production, Algeria, "Country", Algeria]) VAR tbl2 = SELECTCOLUMNS(Table2, "Date", [Month], "Production", [Crude Oil Production, Angola], "Country", Angola]) RETURN UNION (tbl1, tbl2)I understand that the problem is that I do not have currently columns names as such to add via SELECTCOLUMNS. Any possible solutions to this problem?
Solved! Go to Solution.
@Anonymous it should be like below, the best would be to do it in power query.
newTable = VAR tbl1 = SELECTCOLUMNS(Table2, "Date", [Month], "Production", [Crude Oil Production, Algeria], "Country", "Algeria") VAR tbl2 = SELECTCOLUMNS(Table2, "Date", [Month], "Production", [Crude Oil Production, Angola], "Country", "Angola") RETURN UNION (tbl1, tbl2)
Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!
Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo
If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤
Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.
@Anonymous it should be like below, the best would be to do it in power query.
newTable = VAR tbl1 = SELECTCOLUMNS(Table2, "Date", [Month], "Production", [Crude Oil Production, Algeria], "Country", "Algeria") VAR tbl2 = SELECTCOLUMNS(Table2, "Date", [Month], "Production", [Crude Oil Production, Angola], "Country", "Angola") RETURN UNION (tbl1, tbl2)
Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!
Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo
If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤
Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.
I used this code as a solution:
newTable = VAR tbl1 = SELECTCOLUMNS(Table2, "Date", [Month], "Production", [Crude Oil Production, Algeria], "Country", "Algeria") VAR tbl2 = SELECTCOLUMNS(Table2, "Date", [Month], "Production", [Crude Oil Production, Angola], "Country", "Angola") VAR tbl3 = SELECTCOLUMNS(Table2, "Date", [Month], "Production", [Crude Oil Production, Ecuador], "Country", "Ecuador") VAR tbl4 = SELECTCOLUMNS(Table2, "Date", [Month], "Production", [Crude Oil Production, Gabon], "Country", "Gabon") VAR tbl5 = SELECTCOLUMNS(Table2, "Date", [Month], "Production", [Crude Oil Production, Iran], "Country", "Iran") VAR tbl6 = SELECTCOLUMNS(Table2, "Date", [Month], "Production", [Crude Oil Production, Iraq], "Country", "Iraq") VAR tbl7 = SELECTCOLUMNS(Table2, "Date", [Month], "Production", [Crude Oil Production, Kuwait], "Country", "Kuwait") VAR tbl8 = SELECTCOLUMNS(Table2, "Date", [Month], "Production", [Crude Oil Production, Libya], "Country", "Libya") VAR tbl9 = SELECTCOLUMNS(Table2, "Date", [Month], "Production", [Crude Oil Production, Nigeria], "Country", "Nigeria") VAR tbl10 = SELECTCOLUMNS(Table2, "Date", [Month], "Production", [Crude Oil Production, Qatar], "Country", "Qatar") VAR tbl11 = SELECTCOLUMNS(Table2, "Date", [Month], "Production", [Crude Oil Production, Saudi Arabia], "Country", "Saudi Arabia") VAR tbl12 = SELECTCOLUMNS(Table2, "Date", [Month], "Production", [Crude Oil Production, United Arab Emirates], "Country", "United Arab Emirates") VAR tbl13 = SELECTCOLUMNS(Table2, "Date", [Month], "Production", [Crude Oil Production, Venezuela], "Country", "Venezuela") RETURN UNION(tbl1, tbl2, tbl3, tbl4, tbl5, tbl6, tbl7, tbl8, tbl9, tbl10, tbl11, tbl12, tbl13)
Unfortunately it makes a duplicate of every row. Is there a reason for it, and how could I fix this?
@Anonymous as I mentioned it is much easier to do it in Power Query than using DAX
Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!
Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo
If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤
Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.
Thank you for your reply. It worked!
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
114 | |
97 | |
86 | |
70 | |
62 |
User | Count |
---|---|
151 | |
120 | |
103 | |
87 | |
68 |