Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

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.

Reply
Syndicate_Admin
Administrator
Administrator

Override column dynamization with DAX

Hello!

I have a problem with a data model table connected through Direct Query. The table has customer information, and there I have columns that should be grouped into one, such as the survey date (date when different surveys were done), it looks like this:

sirjabo_1-1622342638661.png

The "Recent Date" column indicates the last survey answered. My question is how to unmout the pivot of columns without Power Query, because the Direct Query connection does not allow me to.

My goal is to record all completed surveys in a single date column.

I hope I've explained myself correctly,

I appreciate it!

1 ACCEPTED SOLUTION
PaulDBrown
Community Champion
Community Champion

Lett's assume the 'Original' table is:

Table.JPG

You can create a new table using DAX with the following:

 

Unpivoted Table =
VAR F0 =
    ADDCOLUMNS (
        SELECTCOLUMNS (
            'Original Table',
            "ID Cliente", 'Original Table'[ID Cliente],
            "Fecha", 'Original Table'[Fecha Reciente]
        ),
        "Fase", "Fecha Reciente"
    )
VAR F1 =
    ADDCOLUMNS (
        SELECTCOLUMNS (
            'Original Table',
            "ID Cliente", 'Original Table'[ID Cliente],
            "Fecha", 'Original Table'[Fecha Reciente -1 ]
        ),
        "Fase", "Fecha Reciente -1"
    )
VAR F2 =
    ADDCOLUMNS (
        SELECTCOLUMNS (
            'Original Table',
            "ID Cliente", 'Original Table'[ID Cliente],
            "Fecha", 'Original Table'[Fecha Reciente -2]
        ),
        "Fase", "Fecha Reciente -2"
    )
VAR F3 =
    ADDCOLUMNS (
        SELECTCOLUMNS (
            'Original Table',
            "ID Cliente", 'Original Table'[ID Cliente],
            "Fecha", 'Original Table'[Fecha Reciente -3 ]
        ),
        "Fase", "Fecha Reciente -3"
    )
VAR F4 =
    ADDCOLUMNS (
        SELECTCOLUMNS (
            'Original Table',
            "ID Cliente", 'Original Table'[ID Cliente],
            "Fecha", 'Original Table'[Fecha reciente -4]
        ),
        "Fase", "Fecha Reciente -4"
    )
RETURN
    UNION ( F0, F1, F2, F3, F4 )

 

 

and you get this:

Result.JPG

 





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






View solution in original post

1 REPLY 1
PaulDBrown
Community Champion
Community Champion

Lett's assume the 'Original' table is:

Table.JPG

You can create a new table using DAX with the following:

 

Unpivoted Table =
VAR F0 =
    ADDCOLUMNS (
        SELECTCOLUMNS (
            'Original Table',
            "ID Cliente", 'Original Table'[ID Cliente],
            "Fecha", 'Original Table'[Fecha Reciente]
        ),
        "Fase", "Fecha Reciente"
    )
VAR F1 =
    ADDCOLUMNS (
        SELECTCOLUMNS (
            'Original Table',
            "ID Cliente", 'Original Table'[ID Cliente],
            "Fecha", 'Original Table'[Fecha Reciente -1 ]
        ),
        "Fase", "Fecha Reciente -1"
    )
VAR F2 =
    ADDCOLUMNS (
        SELECTCOLUMNS (
            'Original Table',
            "ID Cliente", 'Original Table'[ID Cliente],
            "Fecha", 'Original Table'[Fecha Reciente -2]
        ),
        "Fase", "Fecha Reciente -2"
    )
VAR F3 =
    ADDCOLUMNS (
        SELECTCOLUMNS (
            'Original Table',
            "ID Cliente", 'Original Table'[ID Cliente],
            "Fecha", 'Original Table'[Fecha Reciente -3 ]
        ),
        "Fase", "Fecha Reciente -3"
    )
VAR F4 =
    ADDCOLUMNS (
        SELECTCOLUMNS (
            'Original Table',
            "ID Cliente", 'Original Table'[ID Cliente],
            "Fecha", 'Original Table'[Fecha reciente -4]
        ),
        "Fase", "Fecha Reciente -4"
    )
RETURN
    UNION ( F0, F1, F2, F3, F4 )

 

 

and you get this:

Result.JPG

 





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.