Forum Discussion

chamue329's avatar
chamue329
Icon for Helper II rankHelper II
6 years ago
Solved

Daily 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...
  • az38's avatar
    6 years ago

    chamue329 

    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)