Forum Discussion
Split multiple columns into rows using DAX
- 2 years ago
Hi,
I am not sure if I understood your question correctly, but please check the below and the attached pbix file.
Expected result table = VAR _t = GENERATESERIES ( 1, 100, 1 ) VAR _pathitem = ADDCOLUMNS ( Data, "@path", SUBSTITUTE ( Data[List of Students], ",", "|" ) ) VAR _pathitemsinging = ADDCOLUMNS ( Data, "@pathsinging", SUBSTITUTE ( Data[Singing], ",", "|" ) ) VAR _pathitemdancing = ADDCOLUMNS ( Data, "@pathdancing", SUBSTITUTE ( Data[Dancing], ",", "|" ) ) VAR _generatetable = FILTER ( GENERATE ( _t, ADDCOLUMNS ( _pathitem, "@Students", PATHITEM ( [@path], [Value] ) ) ), [@Students] <> BLANK () ) VAR _generatesinging = SUMMARIZE ( FILTER ( GENERATE ( _t, ADDCOLUMNS ( _pathitemsinging, "@sing", PATHITEM ( [@pathsinging], [Value] ) ) ), [@sing] <> BLANK () ), Data[ID], Data[Class Name], [@sing] ) VAR _generatedancing = SUMMARIZE ( FILTER ( GENERATE ( _t, ADDCOLUMNS ( _pathitemdancing, "@dance", PATHITEM ( [@pathdancing], [Value] ) ) ), [@dance] <> BLANK () ), Data[ID], Data[Class Name], [@dance] ) RETURN SUMMARIZE ( ADDCOLUMNS ( _generatetable, "@activity", SWITCH ( TRUE (), COUNTROWS ( FILTER ( _generatesinging, Data[ID] = EARLIER ( Data[ID] ) && Data[Class Name] = EARLIER ( Data[Class Name] ) && [@Students] = [@sing] ) ) >= 1 && COUNTROWS ( FILTER ( _generatedancing, Data[ID] = EARLIER ( Data[ID] ) && Data[Class Name] = EARLIER ( Data[Class Name] ) && [@Students] = [@dance] ) ) >= 1, "Sing,Dance", COUNTROWS ( FILTER ( _generatesinging, Data[ID] = EARLIER ( Data[ID] ) && Data[Class Name] = EARLIER ( Data[Class Name] ) && [@Students] = [@sing] ) ) >= 1, "Sing", COUNTROWS ( FILTER ( _generatedancing, Data[ID] = EARLIER ( Data[ID] ) && Data[Class Name] = EARLIER ( Data[Class Name] ) && [@Students] = [@dance] ) ) >= 1, "Dance" ) ), Data[ID], Data[Class Name], [@Students], [@activity] )
Certainly! To achieve matching based on values in DAX, you can use relationships and create calculated columns or measures depending on your requirements. Assuming you have two tables, 'Achieved' and 'To Achieve', and they share a common column (let's say 'ID' for demonstration purposes), you can create relationships between them. Then, you can use DAX formulas to achieve matching.
Here's an example using calculated columns:
Table 3 ('To Achieve') =
VAR CurrentID = 'To Achieve'[ID]
RETURN
CALCULATE(
MAX('Achieved'[Value]),
'Achieved'[ID] = CurrentID
)
This formula assumes that 'To Achieve' and 'Achieved' tables have a relationship based on the 'ID' column. It looks up the corresponding 'Value' from the 'Achieved' table for each row in the 'To Achieve' table.
If you need to create a measure instead, you can use similar logic within the CALCULATE function.
Remember to adjust the column and table names according to your actual data structure. If you have multiple columns to match on, you might need to adjust the formula accordingly.
If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly.
In case there is still a problem, please feel free and explain your issue in detail, It will be my pleasure to assist you in any way I can.