Advance your Data & AI career with 50 days of live learning, dataviz contests, hands-on challenges, study groups & certifications and more!
Get registeredJoin us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM. Register now.
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 | Category | Cost |
| 1/1/2024 | B | 5 |
| 2/1/2024 | C | 4 |
| 2/1/2024 | A | 3 |
Dimension Table Date :
Date |
| 1/1/2024 |
2/1/2024 |
| 3/1/2024 |
Dimension Table Category :
| Category |
| A |
| B |
| C |
The intended outcome based on the summarize table should look like this :
Table Summarized :
| Date | Category | Sales | Cost |
| 1/1/2024 | A | 10 | |
| 1/1/2024 | B | 15 | 5 |
| 2/1/2024 | A | 12 | 3 |
| 2/1/2024 | C | 4 |
Appreciate any help !
Solved! Go to Solution.
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]
)
)
Best Regards,
Samarth
If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin
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]
)
)
Best Regards,
Samarth
If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin
@velvetine_123 , Either you can use Join in Power Query to merge these tables by going to Home selecte merge query option or you can create summarized table by going to modelling view and selecting new table using below mentioned DAX
Proud to be a Super User! |
|
Hey thanks for your response, but i keep getting error saying the number the number of columns in UNION are not the same. I've been trying to figure it out but I cant. Wondering if you know what is that about ?
| User | Count |
|---|---|
| 8 | |
| 6 | |
| 3 | |
| 3 | |
| 3 |
| User | Count |
|---|---|
| 11 | |
| 9 | |
| 8 | |
| 7 | |
| 6 |