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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
mariases94
Helper III
Helper III

Previousmonth with Calculate and Userelationship

Hi,

 

I need help with my model. I try to compare the leads we have won this month with the last month. I use the next formula:

 

PrevMonth WIN LEADS = CALCULATE(Opo[Leads ganados], PREVIOUSMONTH(dateadd(Opo[Fecha de cierre real],-1,month)),
USERELATIONSHIP(Opo[Fecha de cierre real],Calendario[Date]))
 
But if I use this formula, it shows me a BLANK.
 
Where is the mistake? Is in the formula? Maybe in the relationships?
 
Thanks for the help.
 
 
1 ACCEPTED SOLUTION

 

 

 

PREVIOUSMONTH(dateadd(Opo[Fecha de cierre real],-1,month))

 

 

 

means "go back one month and then take ALL DATES from the month before"

use 

 

 

 

PREVIOUSMONTH(Opo[Fecha de cierre real])

 

 

 

instead if you want ALL DATES from the previous month,

or 

 

dateadd(Opo[Fecha de cierre real],-1,month)

 

if you want to shift all the dates by a month into the past.

Power BI DAX: DATEADD versus PREVIOUSMONTH – Minova

View solution in original post

6 REPLIES 6
ryan_mayu
Super User
Super User

@mariases94 

https://docs.microsoft.com/en-us/dax/previousmonth-function-dax

https://docs.microsoft.com/en-us/dax/dateadd-function-dax

use either previousmonth or dateadd.  





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Hi @ryan_mayu,

 

I use the two formulas, but it return me blanks again...how can I solve it?

@mariases94 

what's the formula you are using now?

maybe you can try

PrevMonth WIN LEADS = CALCULATE(Opo[Leads ganados],dateadd(Calendario[Date],-1,month),

USERELATIONSHIP(Opo[Fecha de cierre real],Calendario[Date]))





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




 

 

 

PREVIOUSMONTH(dateadd(Opo[Fecha de cierre real],-1,month))

 

 

 

means "go back one month and then take ALL DATES from the month before"

use 

 

 

 

PREVIOUSMONTH(Opo[Fecha de cierre real])

 

 

 

instead if you want ALL DATES from the previous month,

or 

 

dateadd(Opo[Fecha de cierre real],-1,month)

 

if you want to shift all the dates by a month into the past.

Power BI DAX: DATEADD versus PREVIOUSMONTH – Minova

lbendlin
Super User
Super User

You are basically applying Previous month twice.  What made you choose USERELATIONSHIP?  It is not required here.

Hi @lbendlin,

 

I can't saw where I use two times "previousmonth".

 

I have 5 date columns in the principal table, so I made 5 relations between de column "date" of the calendar table with each column type date of the principal table. I use USERELATIONSHIP because I have to use the relation with the other date column. For example, if I want to use "fecha alta" I use USERELATIONSHIP to switch the relation. Because I don't know how to pick another column type date if I don't use USERELATIONSHIP...

 

mariases94_0-1627633394475.png

 

 

**I have to say that I use PBI since may and I'm noobie with it and there are some things that I don't understand at all.

 

Thanks,

 

Maria.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

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

Feb2025 NL Carousel

Fabric Community Update - February 2025

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