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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
brickanalyst
Resolver I
Resolver I

I have a sql query that I'd like to code in dax, how can I achieve this?

Hello there,

Before I come here and ask this question. I asked chatgpt 3.5 to answer my question and I didn't like its answer.

Suppose we have a basic sql query here below:

 

SELECT 
	bt.file_hash,
	bt.project_code,
	(y.cat1_cost - bt.cat1_cost ) / bt.cat1_cost AS variance_cat1_cost 
FROM
	bluetable as bt
INNER JOIN yellowtable as y 
ON bt.file_hash = y.file_hash and bt.cat10 = y.cat10
GROUP BY 
	bt.file_hash,
	bt.project_code

 

 
and I get this answer below: 

 

EVALUATE
    SUMMARIZECOLUMNS (
        bt[file_hash],
        bt[project_code],
        "variance_cat1_cost",
        DIVIDE ( (SUM ( y[cat1_cost] ) - SUM ( bt[cat1_cost] )), SUM ( bt[cat1_cost] ))
    )

 


and it says you don't have to specificy join condition because power bi it's based on common columns.
I doesn't make any sense, this is my join and that's how I get unique records. 

Can someone explain me or guide me how I can create a calculated table with dax with aggregation included?
any video, link or code please.

Thanks!

1 ACCEPTED SOLUTION
brickanalyst
Resolver I
Resolver I

@jgeddes Sorry for late response, I went with sql query so that I couldn load any way that I wanted.
However, we could do distinct column (mutual) to create a table and adding other columns with RELATED function to find corresponding value on the second table, so that I could use this as completing the third table.


These two article are helpful to get the columns you like and join them together, but in my case I needed to do something different.

Edit: I found this article, I believe if I digged into this I could've found my solution on your approach as well.
https://www.sqlbi.com/articles/from-sql-to-dax-joining-tables/

Thanks again!

View solution in original post

2 REPLIES 2
brickanalyst
Resolver I
Resolver I

@jgeddes Sorry for late response, I went with sql query so that I couldn load any way that I wanted.
However, we could do distinct column (mutual) to create a table and adding other columns with RELATED function to find corresponding value on the second table, so that I could use this as completing the third table.


These two article are helpful to get the columns you like and join them together, but in my case I needed to do something different.

Edit: I found this article, I believe if I digged into this I could've found my solution on your approach as well.
https://www.sqlbi.com/articles/from-sql-to-dax-joining-tables/

Thanks again!

jgeddes
Super User
Super User

The answer you got would rely on a relationship being in place between the two tables. 
Here is a link to an article that explains join functions in DAX.
https://www.sqlbi.com/articles/using-join-functions-in-dax/ 

and a link to the NATURALINNERJOIN DAX function

https://learn.microsoft.com/en-us/dax/naturalinnerjoin-function-dax 

 

 

 Hope this gets you pointed in the right direction.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.