The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredCompete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.
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.
@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])
@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
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
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
User | Count |
---|---|
25 | |
10 | |
8 | |
6 | |
6 |
User | Count |
---|---|
31 | |
12 | |
10 | |
10 | |
9 |