Forum Discussion
Dynamic column generation using DAX
axiosfabric Not really understanding this at all. Can you post sample data and expected output?
Sorry, having trouble following, can you post sample data as text and expected output?
Not really enough information to go on, please first check if your issue is a common issue listed here: https://community.powerbi.com/t5/Community-Blog/Before-You-Post-Read-This/ba-p/1116882
Also, please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490
The most important parts are:
1. Sample data as text, use the table tool in the editing bar
2. Expected output from sample data
3. Explanation in words of how to get from 1. to 2.
Training =
| Prof | Code | hrs |
| User 1 | DP101 | 2 |
| User 2 | DP103 | 2 |
| User 3 | DP102 | 2 |
| User 4 | DP320 | 2 |
| User 1 | DP320 | 2 |
Expected table result
| Prof | DP101 | DP103 | DP102 | DP320 |
| User 1 | 2 | 2 | ||
| User 2 | 2 | |||
| User 3 | 2 | |||
| User 4 | 2 |
based on this below code I can achive the above format
PROFSUMMARY =
SUMMARIZE (
Training,
Training[ID],
Training[Prof],
"DP101", CALCULATE ( SUM ( Training[Att Hrs] ), Training[Code] = "DP101",Training[Mode] = "Virtual" ),
"DP103", CALCULATE ( SUM ( Training[Att Hrs] ), Training[Code] = "DP103",Training[Mode] = "Virtual" ),
"DP102", CALCULATE ( SUM ( Training[Att Hrs] ), Training[Code] = "DP102",Training[Mode] = "Virtual" ),
"DP320", CALCULATE ( SUM ( Training[Att Hrs] ), Training[Code] = "DP320",Training[Mode] = "Virtual" ),
)
but here I need to mention the "DP101" as hard coded
"DP101", CALCULATE ( SUM ( Training[Att Hrs] ), Training[Code] = "DP101",Training[Mode] = "Virtual" ),
I need to generate this section dynamically based on the the distinct code availble