Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
jeronimo2334
Helper III
Helper III

Complex SQL to DAX

I have a SQL query that does aggregations between tables that join on multiple columns.

When I try to import this query the server times out, so I imported the tables hoping I could use an equivalent DAX query.

 

Thanks in advance.

 

SELECT
	d.description AS 'description',
	d.id_number AS 'ID Number',
	d.accnt_type AS 'Account Type',
	d.dbtpaytype AS 'Paycode',
	d.first_name AS 'First',
	d.last_name AS 'Last',
	s.payment,
	s.Charges,
	t.payment,
	t.Payments,
	( COALESCE ( t.Payments, 0 ) - COALESCE ( s.Charges, 0 ) ) AS Balance 
	FROM
		StAccount d
		LEFT JOIN (
		SELECT
			school,
			id_number,
			payment,
			SUM( amount ) AS Charges 
		FROM
			Transact
		GROUP BY
			id_number,
			payment,
			school 
		) s ON ( s.id_number = d.id_number AND s.school = d.school AND s.payment = d.dbtpaytype )
		LEFT JOIN (
		SELECT
			school,
			id_number,
			payment,
			SUM( amount ) AS Payments 
		FROM
			Transfer
		WHERE
			type = 'Dep' 
		GROUP BY
			id_number,
			payment,
			school 
		) t ON ( t.id_number = d.id_number AND t.school = d.school AND t.payment = d.dbtpaytype ) 
	WHERE
		 d.debit = 1 
	GROUP BY
		d.id_number 
4 REPLIES 4
v-xuding-msft
Community Support
Community Support

Hi @jeronimo2334 ,

For joining tables, there is a blog you can reference to change SQL to DAX.

 

Best Regards,

Xue

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Best Regards,
Xue Ding
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
jeronimo2334
Helper III
Helper III

@Anonymous 

 

As far as I know Power Query can not handle multiple joins.

Anonymous
Not applicable

@jeronimo2334 

 

I am not aware of your data size however you can try this.

 

https://www.dropbox.com/s/3bbqthegu6f6uzv/Complex%20SQL%20to%20DAX.pbix?dl=0

 

On heavy data this solution might not work but you give a try Smiley Happy

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Proud to be Datanaut!

Anonymous
Not applicable

@jeronimo2334 

 

You can do the same steps in Power Query instead.


If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.