Forum Discussion
Create a new table from the Main Table with criteria
- 1 year ago
You can use below DAX code to calculated table
ResultTable =
VAR ClientsCountries =
SUMMARIZE(MainTable, MainTable[Client], MainTable[Country])
VAR Items =
VALUES(MainTable[Item])
RETURN
GENERATE(
ClientsCountries,
ADDCOLUMNS(
Items,
"AmountSold",
CALCULATE(
SUM(MainTable[AmountSold]),
FILTER(
MainTable,
MainTable[Client] = EARLIER(MainTable[Client])
&& MainTable[Country] = EARLIER(MainTable[Country])
&& MainTable[Item] = EARLIER(MainTable[Item])
)
)
)
)
Thanks,
Pankaj Namekar | LinkedInIf this solution helps, please accept it and give a kudos (Like), it would be greatly appreciated.
- 1 year ago
Thanks pankajnamekar25 for the quick reply. By switching [AmountSold] to "Don't Summarize" does the trrick. How can I convert the blanks to a zero or even text? Thank you again. 🙂
Edit: Please ignore. I changed this line of code:
Thanks again. 🙂 P.S. I may be back lol!
You can use below DAX code to calculated table
ResultTable =
VAR ClientsCountries =
SUMMARIZE(MainTable, MainTable[Client], MainTable[Country])
VAR Items =
VALUES(MainTable[Item])
RETURN
GENERATE(
ClientsCountries,
ADDCOLUMNS(
Items,
"AmountSold",
CALCULATE(
SUM(MainTable[AmountSold]),
FILTER(
MainTable,
MainTable[Client] = EARLIER(MainTable[Client])
&& MainTable[Country] = EARLIER(MainTable[Country])
&& MainTable[Item] = EARLIER(MainTable[Item])
)
)
)
)
Thanks,
Pankaj Namekar | LinkedIn
If this solution helps, please accept it and give a kudos (Like), it would be greatly appreciated.
Hi pankajnamekar25 .
I'm hoping you can direct me a little further with this as I need to add something.
This is the current code which you created for me and works brilliantly:-
ResultTable =
VAR ClientsCountries =
SUMMARIZE(MainTable, MainTable[Client], MainTable[Country])
VAR Items =
VALUES(MainTable[Item])
RETURN
GENERATE(
ClientsCountries,
ADDCOLUMNS(
Items,
"AmountSold",
CALCULATE(
SUM(MainTable[AmountSold]),
FILTER(
MainTable,
MainTable[Client] = EARLIER(MainTable[Client])
&& MainTable[Country] = EARLIER(MainTable[Country])
&& MainTable[Item] = EARLIER(MainTable[Item])
)
)
)
)
In the very first line SUMMARIZE(......), am I able to add fields from other tables which I have already created relationships for?
Many thanks. 🙂