Forum Discussion
How to pivot rows to columns with dates using the DAX language?
- 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)
WorkID Requirements Development Testing Production Deployement 100 2/1/2025 2/15/2025 3/1/2025 3/10/2025 105 2/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.
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)
| WorkID | Requirements | Development | Testing | Production Deployement |
| 100 | 2/1/2025 | 2/15/2025 | 3/1/2025 | 3/10/2025 |
| 105 | 2/3/2025 |
- Richtpt11 months ago
Helper I
Thanks!! I went with a version of the first query and it's working great!
Another follow-up question. What if WorkID from TableA doesn't have any Activities in TableB? I still want the WorkID to display.
- Ahmed-Elfeel11 months ago
Super User
Excellent Richtpt!
I am glad the first query worked great! 😊
For your follow-up question :
yes the query already handles that perfectly! The way you have it written will still display WorkIDs even if they have no activities in TableB
The SUMMARIZE() function starts with TableA (which contains all WorkIDs) and then for each activity column it uses CALCULATE() with SELECTEDVALUE()
- If no matching activity exists SELECTEDVALUE() returns Blank
- The WorkID still appears in the results from TableA
The activity columns will just show as blank or null
So the output will be something like this:
WorkID Requirements Development Testing Production Deployment 100 2/1/2025 2/15/2025 3/1/2025 3/10/2025 105 2/3/2025 null null null 110 null null null null I hope this was helpful for you 😅❤️
Best Regards!
- Richtpt11 months ago
Helper I
Ah, I must have done something wrong. Thanks again very much, this has helped so much!!