Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
saipawar
Helper IV
Helper IV

calculate delta between rows based on specific groups in a column

Hi, 

Here's a snapshot of my data - 

peerques.PNG

 

I'd like to create a new column/measure which calculates the difference of the 'Value' based on previous 'Month''s 'Value. The delta should also check the 'Category 4 = Reviews in Month' and for every 'Category 1'. 

Note - 'Month' is not sorted in the dataset by ascending order.

For example - 

here's the desired output example. 

  

Category 3Category 4MonthValueDelta
MeetingReviews in MonthJanuary 2020103-
MeetingReviews in MonthFebruary 202011714
MeetingReviews in MonthMarch 202012811
MeetingReviews in MonthApril 202017345
TeamsReviews in MonthJanuary 2020200-
TeamsReviews in MonthFebruary 20202000
TeamsReviews in MonthMarch 20202011
TeamsReviews in MonthApril 20202021
     
1 ACCEPTED SOLUTION
V-pazhen-msft
Community Support
Community Support

@saipawar 

Please try something like the following :

Delta  = 
  VAR __PreviousMonth = CALCULATE(SUM([Month].[MonthNo]),FILTER('Table',[Month].[MonthNo]=EARLIER('Table'[Month].[MonthNo])-1))
  VAR __Previous = CALCULATE(SUM([Value]),FILTER('Table',[Month].[MonthNo]=__PreviousMonth), FILTER('Table','Table'[Category 3]=EARLIER('Table'[Category 3]) && 'Table'[Category 4]=EARLIER('Table'[Category 4])))

RETURN
IF([Month]=MIN([Month]),BLANK(),[Value]- __Previous)

sample result.JPG


Paul Zheng _ Community Support Team
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
V-pazhen-msft
Community Support
Community Support

@saipawar 

Please try something like the following :

Delta  = 
  VAR __PreviousMonth = CALCULATE(SUM([Month].[MonthNo]),FILTER('Table',[Month].[MonthNo]=EARLIER('Table'[Month].[MonthNo])-1))
  VAR __Previous = CALCULATE(SUM([Value]),FILTER('Table',[Month].[MonthNo]=__PreviousMonth), FILTER('Table','Table'[Category 3]=EARLIER('Table'[Category 3]) && 'Table'[Category 4]=EARLIER('Table'[Category 4])))

RETURN
IF([Month]=MIN([Month]),BLANK(),[Value]- __Previous)

sample result.JPG


Paul Zheng _ Community Support Team
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Greg_Deckler
Super User
Super User

@saipawar  - Should be something along the lines of:

Delta =
  VAR __PreviousDate = MAXX(FILTER('Table',[Category 3] = EARLIER([Category 3]) && [Category 4] = EARLIER([Category 4])),[Month)
  VAR __Previous = MAXX(FILTER('Table',[Category 3] = EARLIER([Category 3]) && [Category 4] = EARLIER([Category 4]) && [Month] = __PreviousMonth),[Value])
RETURN
  [Value] - __Previous

Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.