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

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

Reply
gsed99
Helper III
Helper III

Nested IF Statement with math on column

Hello,

I want to perform an IF Statement on a column which is formatted in YYYYMM. 

I have been able to do this in Excel, but new to DAX and PowerBI.

Here is my formula in Excel:

=IF(RIGHT(A3,2)="01",LEFT(A3,4)-1&13,A3)

When applied to a value that is 201701, it should become 201613, and for any records not ending in 01, they are left alone.

 

I am trying to get this to work in DAX with PowerBI....

Which would translate to DAX:

=IF(RIGHT('Marketing Snapshot'[DateStampMonth],2)="01",LEFT('Marketing Snapshot'[DateStampMonth],4)-1&12,'Marketing Snapshot'[DateStampMonth])

 

Any help will be greatly appreciated!

1 ACCEPTED SOLUTION

I was able to get it to work, had to apply a FORMAT expression on the last part:

 

DateStampMonth New = IF(RIGHT('Marketing Snapshot'[DateStampMonth],2)="01",LEFT('Marketing Snapshot'[DateStampMonth],4)-1&13,FORMAT('Marketing Snapshot'[DateStampMonth],"General Number"))

View solution in original post

3 REPLIES 3
Interkoubess
Solution Sage
Solution Sage

Hi @gsed99,

 

Did you use this formula as a calculated column?

 

Because I have tried it and it worked...

 

 

Let us know...

Hmmm, I get an error saying "Expressions that yield varian data-type cannot be used to define calculated columns."

 

Can you paste the formula that worked for you?

I was able to get it to work, had to apply a FORMAT expression on the last part:

 

DateStampMonth New = IF(RIGHT('Marketing Snapshot'[DateStampMonth],2)="01",LEFT('Marketing Snapshot'[DateStampMonth],4)-1&13,FORMAT('Marketing Snapshot'[DateStampMonth],"General Number"))

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

Vote for your favorite vizzies from the Power BI World Championship submissions!

Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

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

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.