Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago

Data modeling wanted to create new table from existing table

wanted to create new table from existing table

existing table 

CountryJanfebmar
Albania112
Algeria221
Angola112
Angola221
Argentina 11

 

wanted new table like below

Monthtotal
Jan6
feb7
mar7

3 Replies

  • christinepayton's avatar
    christinepayton
    Icon for Most Valuable Professional rankMost Valuable Professional

    Use "unpivot other columns" with country selected in Power Query (there is an option in settings for how you want to aggregate when unpivoting, this looks like "sum"). If you want a second table, you can duplicate or reference the original table before doing this. 

    • Anonymous's avatar
      Anonymous
      Not applicable

      can you elobrate this, i wanted use new table for other visuals like line chart

      • christinepayton's avatar
        christinepayton
        Icon for Most Valuable Professional rankMost Valuable Professional

        Yeah, so like this:

        Duplicate or reference the original table first, if you want a second table (it's in the right-click menu when you select the table in Power Query). That gives you this:

         

        I misspoke about the aggregate during the unpivot, that is only for going in the other direction and pivoting it turns out. But you can still aggregate in other ways such as group and sum in Power Query, or just write a measure in DAX for "Month Total = SUM(Table[Value])" and drop it in a chart. You are going to run into issues with sorting at that point because you're trying to use month names as a date and it's text, so you could add a conditional column and assign the months a number 1-12, then sort by that column (https://learn.microsoft.com/en-us/power-bi/create-reports/desktop-sort-by-column?tabs=powerbi-desktop).

         

        DAX is the better way to go here because it'll let you use the country as a slicer or dimension.