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

Microsoft is giving away 50,000 FREE Microsoft Certification exam vouchers. Get Fabric certified for FREE! Learn more

Reply
Anonymous
Not applicable

sql query to dax equivalent

Hello,

I've been trying to solve an issue with my current dashboard and can't seem to find a solution.

I have the right result when i check it on the database side with sql, but I just seem to be unable to reproduce results in powerbi.
My table schema is basically 4 tables in one to many order:  Projecto->proj_etapa->operacao->qinv

and i need to reproduce the following query in powerBI:

 

SELECT COUNT(*)
     FROM(
     SELECT p.nome, count(distinct d.dimensao) as c
     FROM projecto as p
     JOIN proj_etapa as d
     ON p.nproj = d.nproj
     GROUP BY nome
having c>1) alias;

with the added detail that i have 4 slicers with 1 variable from each table to filter this data too...

I think it should be possible but i have no clue how to get to accurate result.

any help would be greatly appreciated.

1 ACCEPTED SOLUTION
Anonymous
Not applicable

For someone looking for a possible solution to their problem, i eventually found it.

similar to what @amitchandak did but with a little tweak.

countx(
  filter(
    values(dbw_inv_projecto[nome]),
    calculate(
      distinctcount(dbw_inv_proj_etapa[dimensao])
    )> 1
  ),
  calculate(distinctcount(dbw_inv_proj_etapa[dimensao]))
)
 
the end result can be presented in a card. but if you're looking for input for
for a table, use @amitchandak 's solution.
hope this helps someone.

View solution in original post

3 REPLIES 3
amitchandak
Super User
Super User

@Anonymous , Try a measure like

 


Measure =
var _1 = calculate(distinctcount(proj_etapa[dimensao]))
return
sumx(filter(values(projecto[nome]), > _1), _1)

 

Both table should be joined in power bi

 

you can use nome in visual

 

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

@amitchandak, thanks for the reply
but i think there is something missing from your solution.

 

when you use  "filter(values(projecto[nome]), > _1)"

i assume you meant something like: filter(values(projecto[nome]), _1> 1).

if my assumption is right, it still gives me the wrong result.

 

it is giving me the total sum of "dimensao" for all projects instead of giving me the intended result.

Anonymous
Not applicable

For someone looking for a possible solution to their problem, i eventually found it.

similar to what @amitchandak did but with a little tweak.

countx(
  filter(
    values(dbw_inv_projecto[nome]),
    calculate(
      distinctcount(dbw_inv_proj_etapa[dimensao])
    )> 1
  ),
  calculate(distinctcount(dbw_inv_proj_etapa[dimensao]))
)
 
the end result can be presented in a card. but if you're looking for input for
for a table, use @amitchandak 's solution.
hope this helps someone.

Helpful resources

Announcements
PBIApril_Carousel

Power BI Monthly Update - April 2025

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

Notebook Gallery Carousel1

NEW! Community Notebooks Gallery

Explore and share Fabric Notebooks to boost Power BI insights in the new community notebooks gallery.

April2025 Carousel

Fabric Community Update - April 2025

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

Top Solution Authors