Forum Discussion

Richtpt's avatar
Richtpt
Icon for Helper I rankHelper I
11 months ago
Solved

How to pivot rows to columns with dates using the DAX language?

I'm creating a paginated report that uses a semantic model as the data source.  I'm doing a DAX query to get the data.   I've got data that looks like this: WorkID ActivityName ActivityDate ...
  • Ahmed-Elfeel's avatar
    11 months ago

    Hi Richtpt,

    I hope you are doing well 😀❤️

     

    Ok since you are working with a semantic model and need this for a paginated report...here is my solution:

     

    Using SUMMARIZE and SELECTEDVALUE :

    In your paginated report when you set up the dataset that uses the semantic model as Data source use this DAX query:

    EVALUATE
    SUMMARIZE(
        'TableA',
        'TableA'[WorkID],
        "Requirements",
            CALCULATE(
                SELECTEDVALUE('TableB'[ActivityDate]),
                'TableB'[ActivityName] = "Requirements"
            ),
        "Development",
            CALCULATE(
                SELECTEDVALUE('TableB'[ActivityDate]),
                'TableB'[ActivityName] = "Development"
            ),
        "Testing",
            CALCULATE(
                SELECTEDVALUE('TableB'[ActivityDate]),
                'TableB'[ActivityName] = "Testing"
            ),
        "Production Deployment",
            CALCULATE(
                SELECTEDVALUE('TableB'[ActivityDate]),
                'TableB'[ActivityName] = "Production Deployment"
            )
    )
    ORDER BY 'TableA'[WorkID]

     

    If you prefer better performance you can try this:

    Pivoted Data =
    VAR RequirementsTable =
        FILTER(
            'TableB',
            'TableB'[ActivityName] = "Requirements"
        )
    VAR DevelopmentTable =
        FILTER(
            'TableB',
            'TableB'[ActivityName] = "Development"
        )
    VAR TestingTable =
        FILTER(
            'TableB',
            'TableB'[ActivityName] = "Testing"
        )
    VAR ProductionTable =
        FILTER(
            'TableB',
            'TableB'[ActivityName] = "Production Deployment"
        )
    
    RETURN
    SUMMARIZE(
        'TableA',
        'TableA'[WorkID],
        "Requirements",
            CALCULATE(
                SELECTEDVALUE('TableB'[ActivityDate]),
                RequirementsTable
            ),
        "Development",
            CALCULATE(
                SELECTEDVALUE('TableB'[ActivityDate]),
                DevelopmentTable
            ),
        "Testing",
            CALCULATE(
                SELECTEDVALUE('TableB'[ActivityDate]),
                TestingTable
            ),
        "Production Deployment",
            CALCULATE(
                SELECTEDVALUE('TableB'[ActivityDate]),
                ProductionTable
            )
    )
    • Do not forget to change the tables names (based on yours) from your semantic model
    • Make sure the activity names exactly match your data
    • Use the first query with "EVALUATE" in your dataset connection (For Paginated Reports)

    Execute this DAX query in your paginated report dataset (It will return the pivoted data exactly as you wanted)

    WorkIDRequirementsDevelopmentTestingProduction Deployement
    1002/1/20252/15/20253/1/20253/10/2025
    1052/3/2025   

     

    if this post helps, then I would appreciate a thumbs up and mark it as the solution to help the other members find it more quickly.