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

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

Reply
VeraVB
Frequent Visitor

Distinct count of a record set minus what is in another record set

Hi,

I'm trying to make DAX formule from something simple in SQL but I don't get it. 

This is the select statement: 

select distinct rav_accountid
from rav_orderhistory
where rav_fiscalyear = 2022
and rav_accountid not in (
(select distinct rav_accountid
from rav_orderhistory
where rav_fiscalyear = 2021))

;

 

I can count the accounts for 2022 and I can count the ones for 2021, but not the account that exist in 2022 minus the accounts of 2021. 

Is there perhaps a website or an app that can convert SQL to DAX? 

1 ACCEPTED SOLUTION
johnt75
Super User
Super User

You can use VALUES and EXCEPT, along the lines of

Num new in 2022 =
var accounts2021 = CALCULATETABLE( VALUES('Table'[Account ID]), 'Table'[Year created] = 2021)
var accounts2022 = CALCULATETABLE( VALUES('Table'[Account ID]), 'Table'[Year created] = 2022)
return COUNTROWS( EXCEPT( accounts2022, accounts2021) )

View solution in original post

2 REPLIES 2
johnt75
Super User
Super User

You can use VALUES and EXCEPT, along the lines of

Num new in 2022 =
var accounts2021 = CALCULATETABLE( VALUES('Table'[Account ID]), 'Table'[Year created] = 2021)
var accounts2022 = CALCULATETABLE( VALUES('Table'[Account ID]), 'Table'[Year created] = 2022)
return COUNTROWS( EXCEPT( accounts2022, accounts2021) )

Hi John,

Thank you very much, I was actually pretty close, just couldn't exactly nail it. 

 

kind regards,

Vera

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.

March Power BI Update Carousel

Power BI Community Update - March 2026

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