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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
vs531
New Member

Apply filter on CURRENTGROUP

Hi 

I am trying to calculate the difference between the last and previous observations for each ID. In the dataset, I have multiple observations for each ID over time. As a first step, I want to create a new table with the last and previous dates. I m using GROUPBY, but I cannot apply any filter to CURRENTGROUP. What would be a better approach to the problem?

 

Thanks 

 

 

NewTable =

GROUPBY(
    table,table[ID],
    "LastDate",MAXX(CURRENTGROUP(),table[DATE]),
    "PreviousDate", MAXX(FILTER(CURRENTGROUP(), table[DATE] < MAXX(CURRENTGROUP(),table[DATE]),table[DATE] )
    ))

 

vs531_0-1674497590994.png

 

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@vs531 , In case you need a new column

 

Diff =

var _max = maxx(filter(Table, [ID] = earlier([ID]) && [Date] < earlier([Date]) ) , [Date])
return
[Score]- Maxx(filter(Table, [ID] = earlier([ID]) && [Date] =_max ) , [Score])

 

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

View solution in original post

2 REPLIES 2
vs531
New Member

Thanks @amitchandak 

amitchandak
Super User
Super User

@vs531 , In case you need a new column

 

Diff =

var _max = maxx(filter(Table, [ID] = earlier([ID]) && [Date] < earlier([Date]) ) , [Date])
return
[Score]- Maxx(filter(Table, [ID] = earlier([ID]) && [Date] =_max ) , [Score])

 

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

Find out what's new and trending in the Fabric community.