Forum Discussion
Ayappan
Helper III
4 years agoWant to organize my data using Transform Data
Hi , I am having a data like Year Type Sold Cost Price 2020 T1 500 600 1100 2020 T2 200 500 700 2020 T3 500 400 900 2020 T4 800 300 1100 2020 T5 1100 2...
- 4 years ago
Ayappan not sure why you would want to do that 🙂 but I created a dax for this table (looks almost like what you want):
Table With Totals = VAR _data = 'Table' VAR _totlas = ADDCOLUMNS( VALUES('Table'[Year]), "Type", "Total", "Sold", CALCULATE(SUM('Table'[Sold])), "Cost", CALCULATE(SUM('Table'[Cost])), "Price", CALCULATE(SUM('Table'[Price])) ) VAR _union = UNION( _data, _totlas ) VAR _result_with_sorting = ADDCOLUMNS( _union, "Sorting", 'Table'[Year] & RIGHT([Type]) ) RETURN _result_with_sorting
You need to sort the table in the model by the Sorting column like in the photo:
This is the updated file with my solution:
Totals.pbix
Ayappan
Helper III
4 years agoThanks SpartaBI for the response
I want to create a caclulated table with the new structure..
SpartaBI
Community Champion
4 years agoAyappan not sure why you would want to do that 🙂 but I created a dax for this table (looks almost like what you want):
Table With Totals =
VAR _data = 'Table'
VAR _totlas =
ADDCOLUMNS(
VALUES('Table'[Year]),
"Type", "Total",
"Sold", CALCULATE(SUM('Table'[Sold])),
"Cost", CALCULATE(SUM('Table'[Cost])),
"Price", CALCULATE(SUM('Table'[Price]))
)
VAR _union =
UNION(
_data,
_totlas
)
VAR _result_with_sorting =
ADDCOLUMNS(
_union,
"Sorting", 'Table'[Year] & RIGHT([Type])
)
RETURN
_result_with_sorting
You need to sort the table in the model by the Sorting column like in the photo:
This is the updated file with my solution:
Totals.pbix