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
PBI_enthusiast2
Regular Visitor

DAX Measure to Create the Previous Date Sales

 I have a measure that gives the sales over the given date in column B. I am trying to create another measure that would give me a results as in Column C (screenshot below).

Prev.JPG

Data Model:

Prev2.JPG

 

 The measure I have tried, but did not worked as expected.

CALCULATE([Sales_Measure],  FILTER(ALLSELECTED(DimDate), DimDate[Date] <  MAX(DimDate[Date])))
1 ACCEPTED SOLUTION
Ashish_Mathur
Super User
Super User

Hi,

You may download my PBI file from here.

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

5 REPLIES 5
Ashish_Mathur
Super User
Super User

Hi,

You may download my PBI file from here.

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
CNENFRNL
Community Champion
Community Champion

=
CALCULATE (
    LASTNONBLANKVALUE ( DimDate[DateKey], [Sales_Measure] ),
    DimDate[DateKey] < MAX ( DimDate[DateKey] )
)

Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

Greg_Deckler
Super User
Super User

@PBI_enthusiast2 Try:

PD Measure =
  VAR __DateKey = MAX('DimDate'[DateKey])
  VAR __PDKey = MAXX(FILTER(ALL('DimDate'),[DateKey] < __DateKey)
  VAR __Result = CALCULATE([Sales Measure], 'DimDate'[DateKey] = __PDKey)
RETURN
  __Result

@ 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...

Hi @Greg_Deckler and @CNENFRNL.  Could you share the way to solve this with the new WINDOW() and INDEX() functions.

Thank you.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

No comments as I haven't mastered these newly introduced functions. I'm personally no fan for these funcs because they (seem to) sabotage the conciseness and elegance of "old-school" DAX funcs; IMHO they seem to be some replica of Tableau table calculation funcs.


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

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.