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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
NavaneethaRaju
Helper IV
Helper IV

Need Help with Dax- Interview Question

Hi,

 I just shared the interview question that asked to me during on the interview. 

 

Consider we have only 2 dates. 

Date:--------Previous Month

09/01/2022-  Dec

09/02/2022- Jan

 

We have to create a measure or column to show the Previous month of the each date:

I tried PreviousMonth(Table[Date], its returning only jan in February Month. But in January its not returning the Dec Month.

 

I dont know its is possible or not. Please advice.

 

result that i got.

NavaneethaRaju_0-1673255766419.png

 

1 ACCEPTED SOLUTION
FreemanZ
Super User
Super User

hi @NavaneethaRaju 

what about:

Measure or Column = EDATE ( 'Table'[Date], -1 )

or

= MONTH( EDATE ( 'Table'[Date], -1 ))

View solution in original post

5 REPLIES 5
Mikelytics
Resident Rockstar
Resident Rockstar

@NavaneethaRaju 

 

Found another one 🙂

Mikelytics_2-1673256293709.png

 

 

Measure Previous Month = 

MONTH(EOMONTH(MAX(Dates[Date]),-1))

 

 

Best regards
Michael
-----------------------------------------------------
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Appreciate your thumbs up!
@ me in replies or I'll lose your thread.

------------------------------------------------------------------
Visit my blog datenhungrig which I recently started with content about business intelligence and Power BI in German and English or follow me on LinkedIn!
Mikelytics
Resident Rockstar
Resident Rockstar

Hi @NavaneethaRaju 

 

lease try the following

 

base data

Mikelytics_0-1673255981188.png

Mesure and result

Mikelytics_1-1673256157599.png

formula:

Measure Previous Month = 
var var_ReferenceDate = MONTH(MAX(Dates[Date]))
Return
IF(var_ReferenceDate=1,12,var_ReferenceDate-1)

There might be a better solution but this is the quick and dirty one 🙂

 

Best regards
Michael
-----------------------------------------------------
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Appreciate your thumbs up!
@ me in replies or I'll lose your thread.

 

 

 

------------------------------------------------------------------
Visit my blog datenhungrig which I recently started with content about business intelligence and Power BI in German and English or follow me on LinkedIn!
FreemanZ
Super User
Super User

hi @NavaneethaRaju 

what about:

Measure or Column = EDATE ( 'Table'[Date], -1 )

or

= MONTH( EDATE ( 'Table'[Date], -1 ))

Hi @FreemanZ , 

 

Its working,  Thanks for your earliest reply.

you are welcome. Good luck with the interview.

Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

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

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.

Top Solution Authors