Forum Discussion
Need help creating date delta columns
I have a value in a column, eg (visits), and in another column I have the (date). I also have 3 rows for each date, because I have 3 different stores (StoreID) with a vlaue for visits
I want to be able to create a delta column that counts the difference between the visits for the row date, and the last previous date, for each storeID row.
I'm reading the DAX guides but they seem different from the Power query descriptions, whcih are different again in the powerbi desktop.
Any help greatly appreciated!
you may also take a look at lookupvalue() function ...
11 Replies
- warrencowanKudo Collector
This is my data structure btw before anyone asks :smileywink:
Date Visits Store Daily Delta 01/01/2015 3 London ? 01/01/2015 2 London ? 01/01/2015 3 London ? 02/01/2015 5 Leeds ? 02/01/2015 6 Leeds ? 02/01/2015 1 Leeds ? 03/01/2015 3 Manchester ? 03/01/2015 4 Manchester ? 03/01/2015 1 Manchester ? - Greg_DecklerCommunity Champion
Did you really mean to have all the London rows be the same date, all the Leeds rows be the same date, etc.? Or did you mean for each date to have a London row, Leeds row and Manchester row?
It would seem that this would be a good case to user EARLIER but only if your data is sorted on import by Store and Date and even then it is going to mess up when transitioning between stores, unless you imported each store as a separate table.
- warrencowanKudo CollectorHey smoupre, no that what was my gaff. Trying to be to clever for my own good and screwed up the table example. Each city should be on a unique date row.
Eg
01/01/15 manchester
02/01/15 Manchester
03/01/15 Manchester
01/01/15 London
02/01/15 London
Etc etc- konstantinosMemorable Member
Hope this is similar to what you need. Assuming you trying PowerBI Desktop.
First you need to create a Date table in order to have time intelligence measures. Go to the queries pane and select the query & right click - > duplicate or reference the query -> select the date column and remove all others -> remove duplicates in dates -> load.
Now you have 2 tables in data model -> create relantionship between the date columns .
Write the folowing measure ( only works in PBI Designer or excel 2016 preview else you need to create 3 measures - each for every variance) :
Delta :=
VAR totalvisits =SUM ( Table[Visits] )
VAR previousvisits =CALCULATE (SUM ( Table[Visits] );PREVIOUSDAY('calendar'[Date]))
RETURN DIVIDE ( totalvisits - previousvisits ; previousvisits )
Drag the date from the calendar table & and the store from your visits on the report..It should look like this
- warrencowanKudo Collector
Thanks Konstantinos, thats a very helpful and detailed example. I will give it a shot and report back