Forum Discussion
how to pivot a table in-memory? using summarize+addcolumns?
- 10 years ago
Hi Chefe,
According to your description, you need to create a new table based on the exist table, right?
I have tested it on my local environment, here is the sample DAX for you reference.
Create a table
NewTable = SUMMARIZE('Summary',Summary[ID])
Create columns
Amount1 = LOOKUPVALUE('Summary'[Amount],'Summary'[ID],'NewTable'[ID],'Summary'[Leg],"Leg1")
Unit1 = LOOKUPVALUE('Summary'[Unit],'Summary'[ID],'NewTable'[ID],'Summary'[Leg],"Leg1")
Amount2 = LOOKUPVALUE('Summary'[Amount],'Summary'[ID],'NewTable'[ID],'Summary'[Leg],"Leg2")
Unit2 = LOOKUPVALUE('Summary'[Unit],'Summary'[ID],'NewTable'[ID],'Summary'[Leg],"Leg2")
Amount3 = LOOKUPVALUE('Summary'[Amount],'Summary'[ID],'NewTable'[ID],'Summary'[Leg],"Leg3")
Unit3 = LOOKUPVALUE('Summary'[Unit],'Summary'[ID],'NewTable'[ID],'Summary'[Leg],"Leg3")Regards,
Charlie Liao
Hi Chefe,
According to your description, you need to create a new table based on the exist table, right?
I have tested it on my local environment, here is the sample DAX for you reference.
Create a table
NewTable = SUMMARIZE('Summary',Summary[ID])
Create columns
Amount1 = LOOKUPVALUE('Summary'[Amount],'Summary'[ID],'NewTable'[ID],'Summary'[Leg],"Leg1")
Unit1 = LOOKUPVALUE('Summary'[Unit],'Summary'[ID],'NewTable'[ID],'Summary'[Leg],"Leg1")
Amount2 = LOOKUPVALUE('Summary'[Amount],'Summary'[ID],'NewTable'[ID],'Summary'[Leg],"Leg2")
Unit2 = LOOKUPVALUE('Summary'[Unit],'Summary'[ID],'NewTable'[ID],'Summary'[Leg],"Leg2")
Amount3 = LOOKUPVALUE('Summary'[Amount],'Summary'[ID],'NewTable'[ID],'Summary'[Leg],"Leg3")
Unit3 = LOOKUPVALUE('Summary'[Unit],'Summary'[ID],'NewTable'[ID],'Summary'[Leg],"Leg3")
Regards,
Charlie Liao
- chefe10 years ago
Helper II
Hi Charlie
Thanks. Correct, but in-memory, since I do not want to add any more phyisical table objects to my data model.
Do you mind sharing that specific pbix file of yours?
Cheers, chefe
++++++++++++ edit ++++++++++++
Now I got it, thank you. Don't need to share the file now :)
I was totally unaware of the "calculate table" functionality :-O making tables using DAX syntax that otherwise could only be seen using something like DAX Studio (which I cannot install on my machine unfortunately...), so it is the same coding to use in a measure... brilliant. Thanks again ;)
Though I did have to alter your code a bit:
* using =addcolumns() in the formula instead of - I guess - adding calculated columns using the UI
The syntax - which now should be usable as an interim step in any measure (?) - is now as follows:
MyNewTable = ADDCOLUMNS(SUMMARIZE(Table2;Table2[id]) ;"fx leg amount" ;LOOKUPVALUE(Table2[amount] ;Table2[leg #] ;"leg1" ;Table2[id] ;[id] ) ;"fx leg ccy" ;LOOKUPVALUE(Table2[unit] ;Table2[leg #] ;"leg1" ;Table2[id] ;[id] ) ;"base leg amount" ;LOOKUPVALUE(Table2[amount] ;Table2[leg #] ;"leg2" ;Table2[id] ;[id] ) ;"base leg ccy" ;LOOKUPVALUE(Table2[unit] ;Table2[leg #] ;"leg2" ;Table2[id] ;[id] ) )
Problem solved. Thanks again.