This time we’re going bigger than ever. Fabric, Power BI, SQL, AI and more. We're covering it all. You won't want to miss it.
Learn moreDid you hear? There's a new SQL AI Developer certification (DP-800). Start preparing now and be one of the first to get certified. Register now
Hi All,
I need a requirement of implement below sql query in DAX.
Solved! Go to Solution.
Hi @Jilanibasha ,
Modify the measure as below:
Measure =
VAR _table =
CALCULATETABLE (
VALUES ( 'ContactTopic'[ContactKey] ),
FILTER ( ALL ( 'ContactTopic' ), 'ContactTopic'[topic] = "local office" )
)
RETURN
CALCULATE (
COUNTROWS ( 'ContactTopic' ),
FILTER (
ALL ( 'ContactTopic' ),
'ContactTopic'[ContactKey]
IN _table
&& 'ContactTopic'[topic] <> "local office"
)
)
Check my sample .pbix file attached.
Best Regards,
Kelly
Did I answer your question? Mark my post as a solution!
Hi @Jilanibasha ,
Try:
measure =
VAR _table =
CALCULATETABLE (
VALUES ( 'ContactTopic' ),
FILTER ( ALL ( 'ContactTopic' ), 'ContactTopic'[topic] = "local office" )
)
RETURN
CALCULATE (
COUNTROWS ( 'ContactTopic' ),
FILTER (
ALL ( 'ContactTopic' ),
'ContactTopic'[contackey]
IN _table
&& 'ContactTopic'[topic] <> "local office"
)
)
Best Regards,
Kelly
Did I answer your question? Mark my post as a solution!
Hi Kelly,
The above formulae not accepting IN conditon checking with Variable. it is throwing no of arguments is invalid.
'ContactTopic'[contackey] IN _table
Hi @Jilanibasha ,
Modify the measure as below:
Measure =
VAR _table =
CALCULATETABLE (
VALUES ( 'ContactTopic'[ContactKey] ),
FILTER ( ALL ( 'ContactTopic' ), 'ContactTopic'[topic] = "local office" )
)
RETURN
CALCULATE (
COUNTROWS ( 'ContactTopic' ),
FILTER (
ALL ( 'ContactTopic' ),
'ContactTopic'[ContactKey]
IN _table
&& 'ContactTopic'[topic] <> "local office"
)
)
Check my sample .pbix file attached.
Best Regards,
Kelly
Did I answer your question? Mark my post as a solution!
Hello @Jilanibasha ,
I think you can create 2 tables in Power Query.
First Table Using the SQL Query (Table 1):
select distinct contactkey from ContactTopic where topic='local office'
Second Table Using SQL Query to Bring ALL DATA (Table 2):
select * from ContactTopic
In Data model join the 2 tables on contactkey (one to many relationship - Cross Filter to Both).
Then write the following dax formula and see if it works
NumofRecords =
VAR __records =
CALCULATETABLE ( VALUES ( Table2[Contactkey] ), Table1 )
RETURN
SUMX ( __records, CALCULATE ( COUNTROWS( Table2 ), KEEPFILTERS(Table2[topic]<>"local office") ))
Hi @Jilanibasha ,
Can you share more details like sample data and expected output, rather than just sql query?
Thanks,
Pragati
Hi @Pragati11 ,
I have 2 tree maps visuals, if i select on first visual, second visual should get filter, the selected topic should excluded and contactkeys should be in selected topic for first visual. the query woking fine in SQL. need to convert same logic in dax.
and the data is
Thanks for help in advance.
Thanks,
Jilani
Hi @Jilanibasha ,
Always try to share sample data as an attachement. The screen-shot of data doesn't help me if I want to get it in Power BI at my end. 🙂
If I understand your scenario:
Thanks,
Pragati
Check out the April 2026 Power BI update to learn about new features.
Sign up to receive a private message when registration opens and key events begin.
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
| User | Count |
|---|---|
| 35 | |
| 32 | |
| 25 | |
| 23 | |
| 16 |
| User | Count |
|---|---|
| 65 | |
| 50 | |
| 30 | |
| 23 | |
| 23 |