Forum Discussion
groupby
Hi,
I wanted to create a new table, where my expected result should have been like the below
| Account Sector | TERFYTD USD |
| media & entertainment | 2000 |
| Technology | 3000 |
| Telecom | 4000 |
But i am using the below DAX and my results are weird, its not adding up the values from coloumn TER_FYTD_USD (see below table)
new table = GROUPBY(Inbound,Inbound[AccountSector],(Inbound[TER_FYTD_USD]))
| Account Sector | TERFYTD USD |
| media & entertainment | 500 |
| media & entertainment | 500 |
| media & entertainment | 1000 |
| Technology | 1000 |
| Technology | 1000 |
| Technology | 1000 |
| Telecom | 2000 |
| Telecom | 1000 |
| Telecom | 1000 |
8 Replies
- AnonymousNot applicable
Hi vjnvinod,
Use this formula to create your new DAX Table:
NewColumn =
GROUPBY (
Inbound;
Inbound[AccountSector];
"TERFYTD USD"; SUMX ( CURRENTGROUP (); Inbound[TER_FYTD_USD] )
)Regards.
- TomMartensSuper User
Hey,
as Anonymous already presented a correct answer using GROUPBY(), I just want to add some additional information about this function https://www.sqlbi.com/articles/nested-grouping-using-groupby-vs-summarize/ and here the official documentation https://msdn.microsoft.com/en-us/query-bi/dax/groupby-function-dax
But if you do not need GROUPBY you should consider to use SUMMARIZECOLUMNS() instead https://msdn.microsoft.com/en-us/query-bi/dax/summarizecolumns-function-dax) or still SUMMARIZE, because it's much more performant.
The DAX statement using SUMMARIZECOLUMNS:
Table using SUMMARIZECOLUMNS = SUMMARIZECOLUMNS( 'Inbound'[Account Sector],"new column", SUM('Inbound'[TERFYTD USD]) )The perfomance aspect is described in a new DAX book that you will find here: https://www.amazon.com/Beginning-DAX-Power-BI-Intelligence/dp/1484234766/ref=sr_1_1?ie=UTF8&qid=1526070538&sr=8-1&keywords=beginning+dax+with+power+bi by me fellow datanaut Phil_Seamark
Here is the DAX statement using ADDCOLUMNS(SUMMARIZE(...
Table using ADDCOLUMN SUMMARIZE = ADDCOLUMNS( SUMMARIZE( 'Inbound' ,'Inbound'[Account Sector] ) ,"Wrong Result", SUM('Inbound'[TERFYTD USD]) ,"Correct Result", CALCULATE(SUM('Inbound'[TERFYTD USD])) )There is also a great article on sqlbi.com coparing SUMMARIZE and SUMMARIZECOLUMNS: https://www.sqlbi.com/articles/introducing-summarizecolumns/
Hope this gets you started
Regards
Tom
- vjnvinodImpactful Individual
This is really helpful, thanks for sharing this information.
Despite creating this new table and relationship, my data doesn't interacts with each other, not sure why.
- AnonymousNot applicable
table = SUMMARIZE ( Inbound[AccountSector], "Total", SUM ( Inbound[TER_FYTD_USD] ) )