Forum Discussion
Divide previous row by next row
Hi Guys,
I have the following data set:
| Date | Keyword | Count |
| 01-01-2020 | ABCD | 5 |
| 01-01-2020 | DEFG | 2 |
| 01-01-2020 | HIGK | 3 |
| 01-01-2020 | LMNO | 0 |
| 01-01-2020 | PQRS | 3 |
| 01-01-2020 | TUVW | 5 |
| 01-01-2020 | XYZ | 5 |
| 02-01-2020 | ABCD | 3 |
| 02-01-2020 | DEFG | 4 |
| 02-01-2020 | HIGK | 0 |
| 02-01-2020 | LMNO | 6 |
| 02-01-2020 | PQRS | 10 |
| 02-01-2020 | TUVW | 53 |
| 02-01-2020 | XYZ | 12 |
For every Keyword, I need to divide the Keyword previous date by the next keyword date to get the % of increase. This has to be dynamic. For e.g. for Keyword ABCD, I would want to divide 5 which is the count which is for 01-01-2020 BY 3 which is the count of 02-02-2020. SO it will be 5/3 = 67.667%
I tried working on it, but no success. I don't want to do this calculation in excel is it will be updating the excel file everytime the new data comes in, so is there a way to achive it through a custom column & not be a measure. Because I would then want to multiply this value with a new individual record to get the individual calculation as I have a huge amount of data around (1M)
Any help on this is truly appreciated...
Regards,
PrathSable
17 Replies
- AlB
Community Champion
Hi PrathSable
Create a calculated column in your table
Calc Column = VAR previousDate_ = CALCULATE ( MAX ( Table1[Date] ), ALLEXCEPT ( Table1, Table1[Keyword] ), Table1[Date] < EARLIER ( Table1[Date] ) ) VAR previousValue_ = CALCULATE ( DISTINCT ( Table1[Count] ), ALLEXCEPT ( Table1, Table1[Keyword] ), Table1[Date] = previousDate_ ) VAR currentValue_ = Table1[Count] RETURN DIVIDE ( currentValue_, previousValue_ )Please mark the question solved when done and consider giving kudos if posts are helpful.
Contact me privately for support with any larger-scale BI needs, tutoring, etc.
Cheers
- PrathSable
Advocate II
Hi AlB ,
Not sure, what I am doing wrong: I used the same calculation you provided but here is the output in Yellow that I am getting on my actual file:
Any suggestions?
Regards,
PrathSable
- amitchandak
Super User
PrathSable , Try as new column
Last Date = maxx(filter(table,[date]<earlier([date]) && [keyword] =earlier([keyword])),[date])
Ration with Last = divide([Count],maxx(filter(table,[date]=earlier([Last Date ]) && [keyword] =earlier([keyword])),[Count]))In a measure this how you get last value with help from date table
Last Day Non Continous = CALCULATE(sum('Table'[Count]),filter(all('Date'),'Date'[Date] =MAXX(FILTER(all('Date'),'Date'[Date]<max('Date'[Date])),Table['Date'])))
Day behind Sales = CALCULATE(SUM(Table[Count]),dateadd('Date'[Date],-1,Day))- PrathSable
Advocate II
Hi amitchandak : This is close: But what I want to actually achieve is:
Actual values to find
For our formula for 02-01-2020 we get the divide % for 01-02-2020. Any suggestions on how to achieve the above?
Regards,
PrathSable
- AnonymousNot applicable
Hi PrathSable ,
You cna use this measure
Divided Value =VAR previousDate_ =CALCULATE (MAX ( 'Table'[Date] ), FILTER(ALLEXCEPT ( 'Table','Table'[Keyword] ),'Table'[Date] < MAX ( 'Table'[Date] )))VAR previousValue_ =CALCULATE (MAX( 'Table'[Count] ), FILTER(ALLEXCEPT ( 'Table', 'Table'[Keyword] ),'Table'[Date] = previousDate_))RETURNDIVIDE ( previousValue_, MAX('Table'[Count])) * MAX('Table'[Actual])Regards,
Harsh NathaniDid I answer your question? Mark my post as a solution! Appreciate with a Kudos!! (Click the Thumbs Up Button)
- nandukrishnavs
Community Champion
Your example is a bit confusing. 5/3 =67.667?
Try this
Percentage = var nextDate=MINX(FILTER(ALL('Table'),'Table'[Keyword]=EARLIER('Table'[Keyword])&&'Table'[Date]>EARLIER('Table'[Date])),'Table'[Date]) var nextDateValue= SUMX(FILTER(ALL('Table'),'Table'[Date]=nextDate&&'Table'[Keyword]=EARLIER('Table'[Keyword])),'Table'[Count]) return DIVIDE(nextDateValue,[Count],BLANK())You may have to tweak the logic based on your real scenario.
Did I answer your question? Mark my post as a solution!
Appreciate with a kudos 🙂 - speedramps
Super User
Hi Prath
Please consider this solutionEither by using Query Group By or DAX table functions do the following
Create a “now” subset of your original table with just the latest value per keyword.
Create a “remainder” subset of your original table with all records except the records on the above subset.
Create a “before” subset of your “remainder” table with just the latest value per keyword.
You can now report “now” - “before” by keyword.