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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

DATESMTD with filter

Hi,

I want a measure, count the number of ID in the last month (April 2021), where Type = "Semi" and "Complete" and Status = "Approved".

Here is my Data I am using the below DAX still I dont get right answer.

image.png

image.png

image.png

 

My correct answer is 5

 

Thanks !

 

Rakesh

 

1 ACCEPTED SOLUTION
v-xiaotang
Community Support
Community Support

Hi @Anonymous 

I try to reproduce your problem, however, when I input your measure, it returns the correct count:

v-xiaotang_0-1620612937432.png

Can you share you PBI file after removing sensitive information?

 

OR

Try this:

Measure2 =
VAR _m =
    MONTH ( LASTDATE ( DATEADD ( Sheet1[Date], -1, MONTH ) ) )
RETURN
    CALCULATE (
        COUNT ( Sheet1[ID] ),
        FILTER (
            ALL ( Sheet1 ),
            ( Sheet1[Type] = "Semi"
                || Sheet1[Type] = "Completed" )
                && Sheet1[Status] = "Approved"
                && MONTH ( Sheet1[Date] ) = _m
        )
    )

Result:

v-xiaotang_1-1620612937439.png

Hope this helps.

Best Regards,

Community Support Team _ Tang

If this post helps, please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
v-xiaotang
Community Support
Community Support

Hi @Anonymous 

I try to reproduce your problem, however, when I input your measure, it returns the correct count:

v-xiaotang_0-1620612937432.png

Can you share you PBI file after removing sensitive information?

 

OR

Try this:

Measure2 =
VAR _m =
    MONTH ( LASTDATE ( DATEADD ( Sheet1[Date], -1, MONTH ) ) )
RETURN
    CALCULATE (
        COUNT ( Sheet1[ID] ),
        FILTER (
            ALL ( Sheet1 ),
            ( Sheet1[Type] = "Semi"
                || Sheet1[Type] = "Completed" )
                && Sheet1[Status] = "Approved"
                && MONTH ( Sheet1[Date] ) = _m
        )
    )

Result:

v-xiaotang_1-1620612937439.png

Hope this helps.

Best Regards,

Community Support Team _ Tang

If this post helps, please consider Accept it as the solution to help the other members find it more quickly.

amitchandak
Super User
Super User

@Anonymous , Prefer to use a date table for time intelligence and try like

 

calculate(count(Sheet1[ID]), datesmtd(dateadd('Date'[Date],-1, month)), filter(Sheet1, Sheet1[Type] in{ "Semi" , "Complete"} &&Sheet1[Status] = "Approved"))

 

 

To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :radacad sqlbi My Video Series Appreciate your Kudos.

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

@amitchandak ,

This is also not working ,

image.png

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Users online (3,020)