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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Jus10
New Member

Return value from row where row date equals table max date

Hey everyone! First post, but I've used so many of the other threads to get to where I am currently and really appreciate this community!

 

For the below table, I'm trying to write a measure titled CURRENT DATE BALANCE that returns only the rows where the row date is the MAX date in the table. Similarly, I want a second measure for PRIOR DATE BALANCE that returns each row where the row date doesn't equal the table MAX date but only the row with the latest date for duplicate IDs.

 

IDDATEBALANCE
DOC 19/22/2022$0.00
DOC 29/22/2022$2,500.00
DOC 39/22/2022$9,745.51
DOC 19/23/2022$0.00
DOC 29/23/2022$2,500.00
DOC 39/23/2022$9,745.51
DOC 19/26/2022$1,121.89
DOC 49/26/2022$0.00
DOC 39/26/2022$9,745.51
DOC 19/27/2022$2,571.52
DOC 39/27/2022$9,745.51

So from the above table, I'm hoping to get to a solution that looks like the below where rows with a date of 9/27 (max date) show balances under CURRENT DATE and each row with a date less than 9/27, but only the most recently dated row for duplicate IDs, shows under PRIOR DATE. (Date column included below for easier tracking from original table to desired solution)

 

IDCURRENT DATE BALANCEPRIOR DATE BALANCEDATE
DOC 1$2,571.52 9/27/2022
DOC 3$9,745.51 9/27/2022
DOC 2 $2,500.009/23/2022
DOC 4 $0.009/26/2022

 

Below is the current formula I have in my measure, but this is returning all values under CURRENT DATE BALANCE as opposed to what I had hoped for above. I understand why it's doing this now, but I don't know how to fix it.

 

 

CURRENT DATE BALANCE = VAR charge_date = MAX(TABLE1[DATE]) RETURN CALCULATE(SUM(TABLE1[BALANCE]), TABLE1[DATE] = charge_date)

 

 

Thanks!

 

1 REPLY 1
HoangHugo
Solution Specialist
Solution Specialist

Hi, try this one

Current date = CALCULATE(SUM([BALANCE]),ALLSELECTED(table),[DATE] = MAX([DATE])
Prior date = 
var date = MAXX(CALCULATEABLE(SUMMARIZE(data table,[DATE], "row", COUNTROW(data table)),[DATE]<MAX[DATE],[row]>=2),[DATE])
return CALCULATE (SUM([BALANCE]),[DATE]=date)

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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