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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
gsed99
Helper III
Helper III

Filter formula using date field YYYYMM math

Hello,

I am trying to create a filter using a YYYYMM date field, and subtract 1 from another date field. 

Example:

Snapshot Date=YYYYMM (201605)

SQOMonth=YYYYMM (201604)

 

I want to create a measure (or column) that will count # of SQO only if the SQOMonth=Snapshot Date - 1.

Meaning I want to count all SQO's with SQOMonth=201604 with the Snapshot Date=201605, or SQOMonth=201612 with Snapshot Date=201701. The report will be aggregated by SQOMonth.

 

Also, for the December months, I want to use the following January date, so converting 201701 to 201612, or 201601 to 201512. I was thinking a formula like Excel like: IF(Right([Snapshot Date],2="01","12",), but now sure how that can be done in DAX.

 

My guess is something like:

COUNT('Database'[SQOMonth])

FILTER([SQOMonth]=Snapshot Date - 1

 

Any help would be greatly appreciated!

2 REPLIES 2
v-yuta-msft
Community Support
Community Support

Hi gsed99,

 

Try DAX formula below:

Count Result =
CALCULATE (
    COUNT ( Database[SQOMonth] ),
    FILTER ( Database, [SQOMonth] = EDATE ( [Snapshot Date], -1 ) )
)

Regards,

Jimmy Tao

Thank you, it sounds very close, but its giving me an error saying "Too few arguments were passed to the FILTER function."

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.