Forum Discussion

Summitreached's avatar
Summitreached
Frequent Visitor
9 years ago
Solved

Create a new table pivot from calculated columns

Hi,

 

I am very new to this but trying to convert the following table where JAN - DEC are calculated columns:

 

ResourceJanFebMarAprMayJunJulAugSepOctNovDec
A0.51.50.10.10.30.30.30.30.30.30.32
B0.10.10.30.30.30.30.30.30.3211
A0.50.30.10.10.10.30.30.30.30.30.30.3
B0.51.50.10.10.30.30.30.30.30.30.32
etc            

 


into the following: 

 

ResourceMonthValue
AJan1
AFeb1.8
AMar0.2
AApr0.2
AMay0.4
AJun0.6
AJul0.6
AAug0.6
ASep0.6
AOct0.6
ANov0.6
ADec2.3
BJan0.6
BFeb1.6
BMar0.4
BApr0.4
BMay0.6
BJun0.6
BJul0.6
BAug0.6
BSep0.6
BOct2.3
BNov1.3
BDec3

 

 

Note I am ok if Resource is repeated for each instance of Month i.e. two values for Jan for Resource A


I cannot use a query as I have calculated columns and have tried DAX to pivot as follows... but get multiple repeats

 

NewTable=

UNION (

    SELECTCOLUMNS (

        OldTableName,

        "Value", OldTableName[Jan],

        "Month", "Jan",

        "Resource", OldTableName[Resource]

    ),

    SELECTCOLUMNS (

       

OldTableName,

        "Value", OldTableName[Feb],

        "Month", "Feb",

        "Resource", OldTableName[Resource]

    ), etc...

 

Any help greatly appreciated!

 

Killian

  • Anonymous's avatar
    Anonymous
    9 years ago

    Hi Summitreached,

     

    If this is a case, you can try to add a distinct function outside of your formula, this function also works on table.

    NewTable=
    DISTINCT(
    UNION (
        SUMMARIZE(
            OldTableName,
            OldTableName[Resource],
            "Month", "Jan",
    	"Value", OldTableName[Jan]
        ),
    
        SUMMARIZE(
    		OldTableName,
            	OldTableName[Resource],
    		"Month", "Feb",
            	"Value", OldTableName[Feb]
        ), etc...
    )

     

     

    Regards,

    Xiaoxin Sheng

6 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Summitreached,

     

    You can try to use unpivot table function and remove duplicate function to convert these records.

     

    Steps:

     

    1. Click on edit queries button to enter query editor.
    2. Select month columns and click on unpivot table.


    3. All select table and click on remove duplicate button.

     

    Regards,

    Xiaoxin Sheng

    • Summitreached's avatar
      Summitreached
      Frequent Visitor

      Hi Xiaoxin,

       

      Thank you for the quick response. Unfortunately calculated columns do not appear in the Query editor.

       

      Regards,

      Killian

      • Anonymous's avatar
        Anonymous
        Not applicable

        Hi Summitreached,

         

        Can you share the sample data to analysis and write the formula?

         

        Regards,

        Xiaoxin Sheng