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

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply
Anonymous
Not applicable

Excel function to DAX

Hi,

I need some help converting an excel formula into DAX. 

Excel: =DATE(YEAR(TODAY()),MONTH(TODAY())-[@[- Months]]+1,0)

- Months = is a selection with the month number values (1 thru 12)

Result should be: YYYY-DD

- Months    Day

1                 2022-04
2                 2022-03
3                 2022-02
4                 2022-01

 

Any help will be appreciated. Been trying to convert this fucntion for a couple of days now.

Thanks. 

3 REPLIES 3
Jihwan_Kim
Super User
Super User

Hi,

I am not sure if I understood your question correctly, but please check the below picture and the attached pbix file.

It is for creating a new column.

Slide1.jpg

 

Result CC =
VAR _todaymonth =
    MONTH ( TODAY () )
VAR _todayyear =
    YEAR ( TODAY () )
VAR _condition = _todaymonth > 'Months Table'[@Months]
RETURN
    IF (
        _condition = TRUE (),
        (
            _todayyear & "-"
                & FORMAT ( _todaymonth - 'Months Table'[@Months], "00" )
        )
    )

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.
amitchandak
Super User
Super User

@Anonymous , You can create a measure

 

format(DATE(YEAR(TODAY()),MONTH(TODAY())-selectedvalues(month[month])+1,1), "YYYYMM")

 

 

or

 

format(DATE(YEAR(TODAY()),MONTH(TODAY())-selectedvalues(month[month])+1,1), "YYYYDD")

 

or

 

format(DATE(YEAR(TODAY()),MONTH(TODAY())-selectedvalues(month[month])+1,day(Today()) ), "YYYYMM")

 

 

or

 

format(DATE(YEAR(TODAY()),MONTH(TODAY())-selectedvalues(month[month])+1,day(Today()) ), "YYYYDD")

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

Thank you for your reply. I am going to give this a try. 

Should I create measure columns for all excel functions in Power BI?

Thank you again. 

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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