Forum Discussion

puserp's avatar
puserp
Regular Visitor
2 years ago
Solved

transpose some measure/ merge

I have a query resulting in :

[TABLE 1]

Dim1Dim2Dim3Date Measure1Measure 2
axyzabct1m1t1am2t1a
axyzabct2m1t2am2t2a
bbxyzabczt1m1t1bm2t1b
bbxyzabczt2m1t2bm2t2b

 

I want to get the results as

[TABLE 2]

Dim1Dim2Dim3Measure1 t1Measure 2 t1Measure1 t2Measure 2 t2
axyzabcm1t1am2t1am1t2am2t2a
bbxyzabczm1t1bm2t1bm1t2bm2t2b

 

In python that can be done easily with two queries for date 1 and date 2 and then a merge on Dim1 Dim2 DIm 3 with suffixes t1 and t2.
Can I achieve directly my [Table 2] in DAX ?

 

  • Anonymous's avatar
    Anonymous
    2 years ago

    Thanks for the reply from bhanu_gautam , please allow me to provide another insight:

     

    Hi puserp ,

     

    Whether the formula works or not depends on whether the measure1, measure2 in the information you provide is a created measure or a specific field in the table. Refer to the following formula:

    if measure, try below formula:

    Table2 = 
    SUMMARIZECOLUMNS (
        'Table'[Dim1],
        'Table'[Dim2],
        'Table'[Dim3],
        "Measure1 t1", CALCULATE ( [Measure1], 'Table'[Date ] = "t1" ),
        "Measure 2 t1", CALCULATE ( [Measure2], 'Table'[Date ] = "t1" ),
        "Measure1 t2", CALCULATE ( [Measure1], 'Table'[Date ] = "t2" ),
        "Measure 2 t2", CALCULATE ( [Measure2], 'Table'[Date ] = "t2" )
    )
    

     

    if field, try below formula:

    Table3 =
    SUMMARIZECOLUMNS (
        'Table'[Dim1],
        'Table'[Dim2],
        'Table'[Dim3],
        "Measure1 t1", CALCULATE ( MAX ( 'Table'[M1] ), 'Table'[Date ] = "t1" ),
        "Measure 2 t1", CALCULATE ( MAX ( 'Table'[M2] ), 'Table'[Date ] = "t1" ),
        "Measure1 t2", CALCULATE ( MAX ( 'Table'[M1] ), 'Table'[Date ] = "t2" ),
        "Measure 2 t2", CALCULATE ( MAX ( 'Table'[M2] ), 'Table'[Date ] = "t2" )
    )
    

     

    Best Regards,
    Adamk Kong

     

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

     

3 Replies

  • puserp , Try using below method 

     

    Table2 =
    SUMMARIZECOLUMNS (
    'TABLE 1'[Dim1],
    'TABLE 1'[Dim2],
    'TABLE 1'[Dim3],
    "Measure1 t1", CALCULATE ( SUM ( 'TABLE 1'[Measure1] ), 'TABLE 1'[Date] = "t1" ),
    "Measure 2 t1", CALCULATE ( SUM ( 'TABLE 1'[Measure2] ), 'TABLE 1'[Date] = "t1" ),
    "Measure1 t2", CALCULATE ( SUM ( 'TABLE 1'[Measure1] ), 'TABLE 1'[Date] = "t2" ),
    "Measure 2 t2", CALCULATE ( SUM ( 'TABLE 1'[Measure2] ), 'TABLE 1'[Date] = "t2" )
    )

    • puserp's avatar
      puserp
      Regular Visitor

      Thanks, I just can't get the syntax to work, it gives me

      The column "Measure1" in the table "Table 1" is not found and is not used in this expression

      That last one was on me for wrong source of t1 and t2

  • Anonymous's avatar
    Anonymous
    Not applicable

    Thanks for the reply from bhanu_gautam , please allow me to provide another insight:

     

    Hi puserp ,

     

    Whether the formula works or not depends on whether the measure1, measure2 in the information you provide is a created measure or a specific field in the table. Refer to the following formula:

    if measure, try below formula:

    Table2 = 
    SUMMARIZECOLUMNS (
        'Table'[Dim1],
        'Table'[Dim2],
        'Table'[Dim3],
        "Measure1 t1", CALCULATE ( [Measure1], 'Table'[Date ] = "t1" ),
        "Measure 2 t1", CALCULATE ( [Measure2], 'Table'[Date ] = "t1" ),
        "Measure1 t2", CALCULATE ( [Measure1], 'Table'[Date ] = "t2" ),
        "Measure 2 t2", CALCULATE ( [Measure2], 'Table'[Date ] = "t2" )
    )
    

     

    if field, try below formula:

    Table3 =
    SUMMARIZECOLUMNS (
        'Table'[Dim1],
        'Table'[Dim2],
        'Table'[Dim3],
        "Measure1 t1", CALCULATE ( MAX ( 'Table'[M1] ), 'Table'[Date ] = "t1" ),
        "Measure 2 t1", CALCULATE ( MAX ( 'Table'[M2] ), 'Table'[Date ] = "t1" ),
        "Measure1 t2", CALCULATE ( MAX ( 'Table'[M1] ), 'Table'[Date ] = "t2" ),
        "Measure 2 t2", CALCULATE ( MAX ( 'Table'[M2] ), 'Table'[Date ] = "t2" )
    )
    

     

    Best Regards,
    Adamk Kong

     

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.