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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
chillbro5587
Frequent Visitor

Getting Sales from 2 Months Ago - Context Errors

Hi all. I'm having a lot of trouble with something that shouldn't be too hard. I've tried for about 6 hours and haven't gotten past where I was after 1 minute.

 

Problem: Get sales from 2 months ago, be able to display:

1. In a table(4/1/2018 shows 2/1/2018)

2. As a standalone "Card" with sales from 2 months ago from today.

 

#1 is fine. See below

DateAmountSales 2 Months Ago
1/1/2018200 
2/1/2018300 
3/1/2018400200
4/1/2018500300

 

#2 simply shows a sum of all sales instead of the sales from 2 months ago

 

Tables: Date and Sales, joined on Date['DateValue'] and Sales['Date']

 

(Measure) Sales 2 Months Ago:=CALCULATE(SUM(Amount),DATEADD(Date['DateValue'],-2,Month))

What I'm really trying to do is get the sales from the entire month of 2 months ago. It is July now, so I'd want to get sale from:

5/1/2018 to 5/31/2018

  • Edit: I also want this to be able to go into a table, such as in #1

 

Any help would be appreciated.

1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

You should be able to use the techniques as described in my Quick Measure, Time Intelligence, The Hard Way:

 

https://community.powerbi.com/t5/Quick-Measures-Gallery/Time-Intelligence-quot-The-Hard-Way-quot-TIT...

 

So, basically:

 

Sales 2 Months Ago = 
VAR __month = MONTH(MAX([Date]))
VAR __tmpTable = FILTER(ALL(Table11),MONTH([Date])=__month-2)
RETURN
SUMX(__tmpTable,[Amount])

 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

3 REPLIES 3
v-piga-msft
Resident Rockstar
Resident Rockstar

Hi @chillbro5587,

 

The measure from  Greg_Deckler should solve your problem.

 

If you have solved this problem, please always accept the replies making sense as solution to your question so that people who may have the same question can get the solution directly.

 

If you still need help, please share the output you expected, so that we can help further investigate on it?

 

Best Regards,

Cherry

Community Support Team _ Cherry Gao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Greg_Deckler
Super User
Super User

You should be able to use the techniques as described in my Quick Measure, Time Intelligence, The Hard Way:

 

https://community.powerbi.com/t5/Quick-Measures-Gallery/Time-Intelligence-quot-The-Hard-Way-quot-TIT...

 

So, basically:

 

Sales 2 Months Ago = 
VAR __month = MONTH(MAX([Date]))
VAR __tmpTable = FILTER(ALL(Table11),MONTH([Date])=__month-2)
RETURN
SUMX(__tmpTable,[Amount])

 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

What happens if the month is January? 1-2=-1. Does that work?

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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