cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Helper II
Helper II

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 measures?  I've been scouring the message boards but can't seem to find a solution for this scenario. 

 

CustomerDateRunning SalesDaily Chg% Daily Chg
A3/2/202010--
A3/3/20202515150%
A3/4/2020401560%
A3/5/20209757143%
B3/2/2020100--
B3/3/20201202020%
B3/4/20201907058%
B3/5/20202203016%
1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Super User II
Super User II

Re: Daily change rate with multiple customers

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

do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

View solution in original post

6 REPLIES 6
Highlighted
Super User II
Super User II

Re: Daily change rate with multiple customers

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

do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

View solution in original post

Highlighted
Super User IV
Super User IV

Re: Daily change rate with multiple customers

This should be basically the same as MTBF - 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/3395...

 

In your case:

 

Daily Chg =
  VAR __Current = [Running Sales]
  VAR __PreviousDate = 
    MAXX(
      FILTER(
        'Table',
        [Customer] = EARLIER([Customer]) &&
        [Date] < EARLIER([Date])
      ),
      [Date]
    )
  VAR __Previous = 
     MAXX(FILTER('Table',[Customer = EARLIER([Customer]) && [Date] = __PreviousDate),[RunningSales])
RETURN
  __Current - __Previous

---------------------------------------

Putting square pegs in round holes since 1972.

I have a NEW book! 
DAX Cookbook from Packt
Over 120 DAX Recipes!




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Highlighted
Helper II
Helper II

Re: Daily change rate with multiple customers

@az38 This works perfectly.  I was able to trend this out on a line chart and both measures display.  I have a follow-up question, in my table structure there is also a State column. When I add a second filter to my line chart to view it by State, it won't render. Is this simply some chart settings in Power BI to render the visual properly or am I stuck having to create a second set of measures if I wanted to generate for the aggregate of customers by State?  Here's my table field with State included:

 

StateCustomerDateRunning SalesDaily Chg% Daily Chg
CAA3/2/202010--
CAA3/3/20202515150%
CAA3/4/2020401560%
CAA3/5/20209757143%
CAB3/2/2020100--
CAB3/3/20201202020%
CAB3/4/20201907058%
CAB3/5/20202203016%
Highlighted
Helper II
Helper II

Re: Daily change rate with multiple customers

Perhaps a change in the DAX syntax to dynamically adjust to the filter selection (State or Customer) if that is feasible?

Highlighted
Super User II
Super User II

Re: Daily change rate with multiple customers

@chamue329 

in 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)))

do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

Highlighted
Helper II
Helper II

Re: Daily change rate with multiple customers

@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 changeRunning Sales with daily change

Helpful resources

Announcements
Community Blog

Community Blog

Visit our Community Blog for articles, guides, and information created by fellow community members.

Using the Community

Using the Community

Need help with the Power BI Community? Our 'Using the Community' support articles are a great place to start.

Community Summit North America

Community Summit North America

Innovate, Collaborate, Grow. The top training and networking event across the globe for Microsoft Business Applications

Power Platform 2020 release wave 2 plan

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors