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

The FabCon + SQLCon recap series starts April 14th at 8am Pacific. If you’re tracking where AI is going inside Fabric, this first session is a can't miss. Register now

Reply
samnaw
Resolver I
Resolver I

If statement in DAX

Hi

 

I am trying to do a if statement.

 

IF CURRENT(YYYY-MM) = CurrentYearMonth THEN M1

M0M1M2.JPG

 

And I want to put that date in a card. 

 

How can I do this. 

 

 

1 ACCEPTED SOLUTION
samnaw
Resolver I
Resolver I

I did it by creating a column, but I wish i didnt have to create one. 

 

Created a new column: 

 

CurrentYearMonthFlag =
Switch( true(),
[CurrentYearMonth]=FORMAT(today(), "YYYY-MM"),"Yes", "No")
 
DAX statement:
M0Date = CALCULATE
    (SUM(insertDatePLCS[M0]),
        FILTER('insertDatePLCS','insertDatePLCS'[CurrentYearMonthFlag]="Yes"))
 

View solution in original post

6 REPLIES 6
v-weiyan1-msft
Community Support
Community Support

Hi @samnaw ,

 

Based on the sample and description you provided,
You can also consider the following code to create a Measure.

Measure = 
MAXX(
    FILTER('insertDatePLCS',[CurrentYearMonth]=FORMAT(TODAY(), "YYYY-MM")),
    'insertDatePLCS'[M0]
)

Result is as below.

vweiyan1msft_0-1704880929085.png

Is this the result you expect?
Please correct me if I misunderstood your needs.

 

Best Regards,
Yulia Yan

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

samnaw
Resolver I
Resolver I

I did it by creating a column, but I wish i didnt have to create one. 

 

Created a new column: 

 

CurrentYearMonthFlag =
Switch( true(),
[CurrentYearMonth]=FORMAT(today(), "YYYY-MM"),"Yes", "No")
 
DAX statement:
M0Date = CALCULATE
    (SUM(insertDatePLCS[M0]),
        FILTER('insertDatePLCS','insertDatePLCS'[CurrentYearMonthFlag]="Yes"))
 
samnaw
Resolver I
Resolver I

No, I want to insert a card that gives me the date associated with currentYearMonth. With no filters selected. 

 

 

 

samnaw
Resolver I
Resolver I

I am still getting the wrong result:

 

I should be getting "2024-01-01" but I am getting "NULL"

 

IF ( FORMAT ( TODAY(), "YYYY-MM" ) = SELECTEDVALUE( 'insertDatePLCS'[CurrentYearMonth]), SELECTEDVALUE( 'insertDatePLCS'[M0]),"NULL")

can you upload a power bi sample file with the page that you are trying to create? 

erickeu
Advocate I
Advocate I

i assume you want to compare what's selected on a slicer with the current yearMonth right ?? if so then just create a new measure
MeasureX = IF ( FORMAT ( TODAY(), "yyyy-MM" ) = SELECTEDVALUE( 'YOUR_TABLE_NAME'[CurrentYearMonth]), "A","B")


IF This helps, just mark it down as a solution, thanks 🙂

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.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

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