This time we’re going bigger than ever. Fabric, Power BI, SQL, AI and more. We're covering it all. You won't want to miss it.
Learn moreJoin the FabCon + SQLCon recap series. Up next: Power BI, Real-Time Intelligence, IQ and AI, and Data Factory take center stage. All sessions are available on-demand after the live show. Register now
Hi community,
I have some tables related in my model, but I cannot find the correct DAX to group them. In SQL I have the following query which gives me the results. My example is a Sales tables, which has the product, each product belongs to a region, each region belong to a state.
I need to obtain the sum of sales by state.
SELECT s.Name as State_Name , sum(nr_product_sold) as nr_prod_sold
FROM SALES sales
left join PRODUCT p on sales.id_product = p.id_product
left join REGION r on region.id_region = p.id_region
left join STATES s on s.id_state = r.id_state
group by s.Name
Thanks for your help.
Solved! Go to Solution.
can we use merge queries in PQ, we can do the data transform like left join
or you can provide some sample data and the expected output
Proud to be a Super User!
@ryan_mayu Thanks for your contribution on this thread.
Hi @larx_mandel ,
@ryan_mayu provided the method in Power Query Editor, here I have another method to help you achieve the requirement. Please follow the steps below to get it:
1. Assume you have the tables SALES, PRODUCT,REGION and STATES in your data model
2. Create a measure as below
MEASURE =
VAR _statename =
SELECTEDVALUE ( 'STATES'[Name] )
VAR _stateids =
CALCULATETABLE (
VALUES ( 'STATES'[id_state] ),
FILTER ( 'STATES', 'STATES'[Name] = _statename )
)
VAR _regionids =
CALCULATETABLE (
VALUES ( 'REGION'[id_region] ),
FILTER ( 'REGION', 'REGION'[id_state] IN _stateids )
)
VAR _productids =
CALCULATETABLE (
VALUES ( 'PRODUCT'[id_product] ),
FILTER ( 'PRODUCT', 'PRODUCT'[id_region] IN _regionids )
)
VAR _psold =
CALCULATE (
SUM ( 'SALES'[nr_product_sold] ),
FILTER ( 'SALES', 'SALES'[id_product] IN _productids )
)
RETURN
_psold
3. Create table visual and apply the field 'STATES'[Name] and the above measure on it
Best Regards
@ryan_mayu Thanks for your contribution on this thread.
Hi @larx_mandel ,
@ryan_mayu provided the method in Power Query Editor, here I have another method to help you achieve the requirement. Please follow the steps below to get it:
1. Assume you have the tables SALES, PRODUCT,REGION and STATES in your data model
2. Create a measure as below
MEASURE =
VAR _statename =
SELECTEDVALUE ( 'STATES'[Name] )
VAR _stateids =
CALCULATETABLE (
VALUES ( 'STATES'[id_state] ),
FILTER ( 'STATES', 'STATES'[Name] = _statename )
)
VAR _regionids =
CALCULATETABLE (
VALUES ( 'REGION'[id_region] ),
FILTER ( 'REGION', 'REGION'[id_state] IN _stateids )
)
VAR _productids =
CALCULATETABLE (
VALUES ( 'PRODUCT'[id_product] ),
FILTER ( 'PRODUCT', 'PRODUCT'[id_region] IN _regionids )
)
VAR _psold =
CALCULATE (
SUM ( 'SALES'[nr_product_sold] ),
FILTER ( 'SALES', 'SALES'[id_product] IN _productids )
)
RETURN
_psold
3. Create table visual and apply the field 'STATES'[Name] and the above measure on it
Best Regards
can we use merge queries in PQ, we can do the data transform like left join
or you can provide some sample data and the expected output
Proud to be a Super User!
Check out the April 2026 Power BI update to learn about new features.
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
| User | Count |
|---|---|
| 39 | |
| 37 | |
| 31 | |
| 23 | |
| 15 |
| User | Count |
|---|---|
| 76 | |
| 59 | |
| 32 | |
| 31 | |
| 26 |