Forum Discussion
cris1196
3 years agoHelper I
Replicate this SQL query in DAX
Hello everyone. I wanted to know if there was a way to replicate, in mesasures, the following SQL queries in DAX, so that it looks as similar as possible to this: Measure = var variable1 = select...
- 3 years ago
Hi cris1196
The following shall return unique count of customers.
Common Customers = VAR T1 = CALCULATETABLE ( VALUES ( 'Table'[Cutomer] ), 'Table'[first_order] = "True", 'Table'[YearMonth] = 202201 ) VAR T2 = CALCULATETABLE ( VALUES ( 'Table'[Cutomer] ), 'Table'[Day] = 1, 'Table'[YearMonth] = 202201 ) RETURN COUNTROWS ( INTERSECT ( T2, T1 ) )New Customers = VAR T1 = CALCULATETABLE ( VALUES ( 'Table'[Cutomer] ), 'Table'[first_order] = "True", 'Table'[YearMonth] = 202201 ) VAR T2 = CALCULATETABLE ( VALUES ( 'Table'[Cutomer] ), 'Table'[Day] = 1, 'Table'[YearMonth] = 202201 ) RETURN COUNTROWS ( EXCEPT ( T2, T1 ) )
tamerj1
3 years agoCommunity Champion
cris1196
I was hopping that you explain what are trying to achieve not how are you trying to achieve it. However there is a chance that I correctly guessed your requirement. It could be much simpler than you might think. Please try
Common Customers =
VAR CurrentMonth =
SELECTEDVALUE ( 'Table'[YearMonth] )
VAR T1 =
CALCULATETABLE (
VALUES ( 'Table'[Cutomer] ),
'Table'[first_order] = "True",
'Table'[YearMonth] = CurrentMonth - 1,
ALL ( 'Table'[Day] )
)
VAR T2 =
VALUES ( 'Table'[Cutomer] )
RETURN
COUNTROWS ( INTERSECT ( T2, T1 ) )cris1196
3 years agoHelper I
I tried to put examples so I tried to explain it better. Thank you very much for your help