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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

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
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.