Forum Discussion
velvetine_123
2 years agoFrequent Visitor
Create summarized tables with 2 dimensions from multiple tables
Hi, I'm looking to create a summarize table based on the following : Table A : Date Category Sales 1/1/2024 A 10 1/1/2024 B 15 2/1/2024 A 12 Table B : Date...
- 2 years ago
Hi velvetine_123 ,
Please try below code:-
SummarizedTable = VAR _uni = UNION ( SELECTCOLUMNS ( 'Table A', "Date", 'Table A'[Date], "Category", 'Table A'[Category], "Sales", 'Table A'[Sales], "Cost", BLANK () ), SELECTCOLUMNS ( 'Table B', "Date", 'Table B'[Date], "Category", 'Table B'[Category], "Sales", BLANK (), "Cost", 'Table B'[Cost] ) ) RETURN SUMMARIZE ( _uni, [Date], [Category], "Sales", SUMX ( FILTER ( _uni, [Date] = EARLIER ( [Date] ) && [Category] = EARLIER ( [Category] ) ), [Sales] ), "Cost", SUMX ( FILTER ( _uni, [Date] = EARLIER ( [Date] ) && [Category] = EARLIER ( [Category] ) ), [Cost] ) )
Samarth_18
Community Champion
2 years agoHi velvetine_123 ,
Please try below code:-
SummarizedTable =
VAR _uni =
UNION (
SELECTCOLUMNS (
'Table A',
"Date", 'Table A'[Date],
"Category", 'Table A'[Category],
"Sales", 'Table A'[Sales],
"Cost", BLANK ()
),
SELECTCOLUMNS (
'Table B',
"Date", 'Table B'[Date],
"Category", 'Table B'[Category],
"Sales", BLANK (),
"Cost", 'Table B'[Cost]
)
)
RETURN
SUMMARIZE (
_uni,
[Date],
[Category],
"Sales",
SUMX (
FILTER (
_uni,
[Date] = EARLIER ( [Date] )
&& [Category] = EARLIER ( [Category] )
),
[Sales]
),
"Cost",
SUMX (
FILTER (
_uni,
[Date] = EARLIER ( [Date] )
&& [Category] = EARLIER ( [Category] )
),
[Cost]
)
)