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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
Anonymous
Not applicable

Translate SQL Query to DAX

Hello I have an SQL query as follows :

 

SELECT a.School, SUM(a.Value) AS Value
FROM(
select School,max(Value) AS Value from table
group by FileId,School

) a
group by School

 

How do I translate this into DAX ?

1 ACCEPTED SOLUTION
Anonymous
Not applicable

@AnonymousIt's because measure returns table (just like your SQL query). To return single value change measure:

Measure=var tempTable=ADDCOLUMNS(SUMMARIZE('Table','Table'[FileId],'Table'[School]),"max_value",CALCULATE(MAX('Table'[Value])))

return CALCULATE(SUMX(tempTable,[max_value]))

View solution in original post

5 REPLIES 5
Anonymous
Not applicable

@Anonymous Try something like this:

Measure=var tempTable=ADDCOLUMNS(SUMMARIZE('Table','Table'[FileId],'Table'[School]),"max_value",CALCULATE(MAX('Table'[Value])))

return ADDCOLUMNS(SUMMARIZE(tempTable,[School]),"sum_value",CALCULATE(SUMX(tempTable,[max_value])))

Anonymous
Not applicable

Hello, I have created a table graph with 2 columns School and the measure you created. I received the following error :

adnane_k_0-1634629519978.png

 

Anonymous
Not applicable

@AnonymousIt's because measure returns table (just like your SQL query). To return single value change measure:

Measure=var tempTable=ADDCOLUMNS(SUMMARIZE('Table','Table'[FileId],'Table'[School]),"max_value",CALCULATE(MAX('Table'[Value])))

return CALCULATE(SUMX(tempTable,[max_value]))

Anonymous
Not applicable

The measure worked perfectly, but can you please show me how to add a WHERE clause in it ?

 

SELECT a.School, SUM(a.Value) AS Value
FROM(
select School,max(Value) AS Value from table

-- New

WHERE Statut LIKE '%abc%'

--End New
group by FileId,School

) a
group by School

 

 

Thanks a lot man you are a life saver

Anonymous
Not applicable

@Anonymous Replace first parameter of SUMMARIZE function ('Table') with FILTER('Table',SEARCH("abc",'Table'[Statut],1,0)) :

Measure=var tempTable=ADDCOLUMNS(SUMMARIZE(  FILTER('Table',SEARCH("abc",'Table'[Statut],1,0)),'Table'[FileId],'Table'[School]),"max_value",CALCULATE(MAX('Table'[Value])))

return CALCULATE(SUMX(tempTable,[max_value]))

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

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.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.