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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Pbiuserr
Post Prodigy
Post Prodigy

Sum of Value by distinct ID and Latest Date

Hello,

Lets assume I have table

 

ID       Date              Value

ID1     01.01.2022    10

ID1     01.02.2022    10

ID1     01.03.2022    20

ID1     01.04.2022    30

ID2     01.01.2022    20

Expected result - 50 (Value 30 for ID1 with date 1.04.2022 + Value 20 from ID2)

How to do that? Thank you in advance

1 ACCEPTED SOLUTION
lukiz84
Memorable Member
Memorable Member

Hi,

 

add a calculated column to your fact table:

 

IsLastDate :=

CALCULATE(
     MAX(facTable[Date]),
     factTable[ID] = EARLIER(factTable[ID]),
     ALL(factTable[Date]),
     ALL(factTable[Value])
) = factTable[Date]

 

then you can add a measure:

 

SumOfMax = 
CALCULATE(
     SUM(factTable[Value]),
     factTable[IsLastDate]
)

View solution in original post

4 REPLIES 4
lukiz84
Memorable Member
Memorable Member

Hi,

 

add a calculated column to your fact table:

 

IsLastDate :=

CALCULATE(
     MAX(facTable[Date]),
     factTable[ID] = EARLIER(factTable[ID]),
     ALL(factTable[Date]),
     ALL(factTable[Value])
) = factTable[Date]

 

then you can add a measure:

 

SumOfMax = 
CALCULATE(
     SUM(factTable[Value]),
     factTable[IsLastDate]
)

Hi,

Can you do that without calculating a new column?

Here's the solution without a calculated column (kind of ;))

 

VAR tempTbl =
   ADDCOLUMNS(
      yourTable,
      "@IsLastDate",
      CALCULATE(
          MAX(yourTable[Date]), yourTable[ID] = EARLIER(yourTable[ID]), ALL(yourTable)
       ) = yourTable[Date]
    )
RETURN
   SUMX(
       FILTER(tempTbl, [@IsLastDate]),
       [Value] 
   )

 

BR 

Lukas

sure, but it's a little early for my brain to do it 😄

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.