Forum Discussion
chamue329
Helper II
6 years agoDaily change rate with multiple customers
Hi, I have a table with customer sales by date and I need to calculate the daily change and % change (example image below). Is it better to add these two columns in Power Query or create DAX meas...
- 6 years ago
DAX is appropriate solution foryour task.
try create a measures
Daily Chg = var _prevDate = CALCULATE(MAX('Table'[Date]),FILTER(ALL('Table'),'Table'[Customer]=SELECTEDVALUE('Table'[Customer]) && 'Table'[Date]<SELECTEDVALUE('Table'[Date]))) RETURN IF(ISBLANK(_prevDate), BLANK(), SELECTEDVALUE('Table'[Running Sales])-CALCULATE(MAX('Table'[Running Sales]),FILTER(ALL('Table'),'Table'[Customer]=SELECTEDVALUE('Table'[Customer]) && 'Table'[Date]=_prevDate)))and
% Daily Chg = var _prevDate = CALCULATE(MAX('Table'[Date]),FILTER(ALL('Table'),'Table'[Customer]=SELECTEDVALUE('Table'[Customer]) && 'Table'[Date]<SELECTEDVALUE('Table'[Date]))) RETURN IF(ISBLANK(_prevDate), BLANK(), DIVIDE(SELECTEDVALUE('Table'[Running Sales]), CALCULATE(MAX('Table'[Running Sales]),FILTER(ALL('Table'),'Table'[Customer]=SELECTEDVALUE('Table'[Customer]) && 'Table'[Date]=_prevDate))) - 1)
chamue329
Helper II
6 years agoPerhaps a change in the DAX syntax to dynamically adjust to the filter selection (State or Customer) if that is feasible?
az38
Community Champion
6 years agoin my solution it would be like
Daily Chg =
var _prevDate = CALCULATE(MAX('Table'[Date]), FILTER(ALLEXCEPT('Table', 'Table'[Customer],'Table'[State]), 'Table'[Date] < SELECTEDVALUE('Table'[Date])))
RETURN
IF(ISBLANK(_prevDate), BLANK(),
SELECTEDVALUE('Table'[Running Sales]) - CALCULATE(MAX('Table'[Running Sales]), FILTER(ALLEXCEPT('Table', 'Table'[Customer], 'Table'[State]), 'Table'[Date]=_prevDate)))- chamue3296 years ago
Helper II
az38 Thanks for the modification - however I'm getting all negative numbers when I filter to States. It works fine when I have the Customer column included, but once I remove and only look at my table by State, it gets messed up. One clarification - I don't have rows in my tables that aggregate the State records. I placed them in my example table for illustration. I don't know if this will make a difference in your syntax.
Running Sales with daily change