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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
Sharmi_28
Helper I
Helper I

Help with SQL subquery to DAX Please

I have following SQL query. Could you please help me on how to check where clause in DAX. Thank

SELECT
       SUM (ColAmt)
FROM Teams T
WHERE
      (T.DateCol >= FisrtDateofPreviousMonth And T.DateCol <= LastDateofPreviousMonth)    And
      NOT Exists ( SELECT  1  FROM Teams P
                         Where
                               P.Col1 = T.Col1 And
                               P.DateCol >= FisrtDateofCurrentMonth And P.DateCol <= LastDateofCurrentMonth                      
                        )

2 REPLIES 2
bhanu_gautam
Super User
Super User

Hi @Sharmi_28 , In DAX instead of Where clause Filter function can be used, try below mentioned DAX meausure

 

EVALUATE
VAR FirstDateofPreviousMonth = EOMONTH(TODAY(), -2) + 1
VAR LastDateofPreviousMonth = EOMONTH(TODAY(), -1)

VAR FirstDateofCurrentMonth = EOMONTH(TODAY(), -1) + 1
VAR LastDateofCurrentMonth = EOMONTH(TODAY())

RETURN
FILTER(
VALUES(T[Col1], T[Col2], T[Col3], T[DateCol]),
T[DateCol] >= FirstDateofPreviousMonth
&& T[DateCol] <= LastDateofPreviousMonth
&& NOT (
CALCULATETABLE(
VALUES(P[Col1]),
P[Col1] = T[Col1],
P[DateCol] >= FirstDateofCurrentMonth
&& P[DateCol] <= LastDateofCurrentMonth
)
)
)

 

Please accept as solution if it helps




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






Thanks for reply and solution.
I tried to apply your DAX but its not working for me.

I trying something like

Measure =
VAR FirstDateofPreviousMonth = EOMONTH(TODAY(), -2) + 1
VAR LastDateofPreviousMonth = EOMONTH(TODAY(), -1)

VAR FirstDateofCurrentMonth = min(DimCalendar[Date])
VAR LastDateofCurrentMonth = max(DimCalendar[Date])

RETURN
CALCULATE(
Sum(FactTable[Amount]),
FactTable[Date] >= FirstDateofPreviousMonth &&
FactTable[Date] <= LastDateofPreviousMonth
&&
NOT ( FactTable[Code]= FactTable[Code] &&
FactTable[Date] >= FirstDateofCurrentMonth && FactTable[Date] <= LastDateofCurrentMonth
)
)

But its giving error.

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

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.