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
Anonymous
Not applicable

Day over Day Dax question

I have a data set that has a list of 5 different products and daily prices for each, for example

Date    Product    Price

09/09     A            $1.00

09/09     B             $1.50

09/09     C             $0.50

09/08     A             $0.75

09/08     B             $1.25

09/08     C             $1.30

 

I also have a date table set up for this BI report. I need to calculate day over day change and need some help figuring out the DAX. Prices are only published Mon-Friday, so I need the DAX to recognize not to calculate if there isn't a price for the previous date (Ex, weekends and holidays). Maybe the Dax can just take most recent price and the last price and get the difference?

 

Thank you for your help. 

4 REPLIES 4
amitchandak
Super User
Super User

@Anonymous , Try a new column like

new column =
var _max = MAXX(FILTER(Table,[Date] < EARLIER([Date]) && [Product] = EARLIER([Product])),[Date])
return
[Price]- MAXX(FILTER(Table,[Date] =_date && [Product] = EARLIER([Product])),[Price])

Greg_Deckler
Super User
Super User

@Anonymous You need to EARLIER. See my article on Mean Time Between Failure (MTBF) which uses EARLIER: http://community.powerbi.com/t5/Community-Blog/Mean-Time-Between-Failure-MTBF-and-Power-BI/ba-p/339586.
The basic pattern is:
Column = 
  VAR __Current = [Value]
  VAR __PreviousDate = MAXX(FILTER('Table','Table'[Date] < EARLIER('Table'[Date])),[Date])

  VAR __Previous = MAXX(FILTER('Table',[Date]=__PreviousDate),[Value])
RETURN
  __Current - __Previous


@ 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...
Anonymous
Not applicable

This got me close but not exact. Below is a list of the numbers I need vs what the DAX formau you provided is giving me. I think I need to add a filter for product somewhere, but I just can't get it right. I checked on excel using basic formaul of (current-previous)/previous). On my report, I will end up showing these numbers as %Change Day over Day

 

Date          Product      Price        Day over Day change      # retruned from DAX formual

09/01            A             1.4650

09/02            A             1.5100             0.0307                           -0.49670

09/03            A             1.5000             -0.0066                         -0.50000

09/04           A              1.4925            -0.0050                           -0.50250

09/01           B              1.8025

09/02           B              1.9100               0.0596                          -0.36330

09/03           B              2.0525               0.0746                         -0.31580

09/04           B              2.1250               0.0353                           -0.29170

Anonymous
Not applicable

This got me close but not exact. Below is a list of the numbers I need vs what the DAX formau you provided is giving me. I think I need to add a filter for product somewhere, but I just can't get it right. I checked on excel using basic formaul of (current-previous)/previous). On my report, I will end up showing these numbers as %Change Day over Day

 

Date          Product      Price        Day over Day change      # retruned from DAX formual

09/01            A             1.4650

09/02            A             1.5100             0.0307                           -0.49670

09/03            A             1.5000             -0.0066                         -0.50000

09/04           A              1.4925            -0.0050                           -0.50250

09/01           B              1.8025

09/02           B              1.9100               0.0596                          -0.36330

09/03           B              2.0525               0.0746                         -0.31580

09/04           B              2.1250               0.0353                           -0.29170

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.

Top Solution Authors