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
Krzysztof_Hyla
Helper II
Helper II

SUM with LASTDATE independent from other columns

Hi,  

I have following inventory history table with three columns: report date, warehouse location & inventory value:

Table 1.jpg

I'm trying to present only current inventory state.

The following formula calculates correctly currrent inventory value (sum of rows for the last report date):

Current Inventory Balance =
CALCULATE(
SUM('Warehouse History'[Value]),
LASTDATE('Warehouse History'[Date])
)

But when I'm trying to replace [Value] column with it, the table is still showing unwanted rows, though the sum is ok:

Table 2.jpg

Any idea how to remove them, to achieve this result:?

Table 3.jpg

Here is the link to pbix file - hope it works.

1 ACCEPTED SOLUTION
v-yalanwu-msft
Community Support
Community Support

Hi, @Krzysztof_Hyla ;

Please try it.

Current Inventory Balance = 
IF(MAX([Date])=CALCULATE( LASTDATE('Warehouse History'[Date]),ALL('Warehouse History')),
CALCULATE(                                     
  SUM('Warehouse History'[Value]),
  LASTDATE('Warehouse History'[Date])))

The final output is shown below:

vyalanwumsft_0-1639019182592.png

Best Regards,
Community Support Team_ Yalan Wu
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

4 REPLIES 4
v-yalanwu-msft
Community Support
Community Support

Hi, @Krzysztof_Hyla ;

Please try it.

Current Inventory Balance = 
IF(MAX([Date])=CALCULATE( LASTDATE('Warehouse History'[Date]),ALL('Warehouse History')),
CALCULATE(                                     
  SUM('Warehouse History'[Value]),
  LASTDATE('Warehouse History'[Date])))

The final output is shown below:

vyalanwumsft_0-1639019182592.png

Best Regards,
Community Support Team_ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

This gave me exactly what I needed - thanks a lot!

Krzysztof_Hyla
Helper II
Helper II

I have used this measure, but no luck so far:

Table 4.jpg

 Here is the exact code I've used:

 

Amitchandak Measure =
VAR __id = MAX ('Warehouse History'[Location] )
VAR __date =
CALCULATE (
MAX('Warehouse History'[Date] ),
ALLSELECTED ('Warehouse History' ),
'Warehouse History'[Location] = __id )
RETURN
CALCULATE (
SUM('Warehouse History'[Value]),
VALUES ('Warehouse History'[Location] ),
'Warehouse History'[Location] = __id,'Warehouse History'[Date] = __date
)
 
I need to somehow hide the first 3 rows.
amitchandak
Super User
Super User

@Krzysztof_Hyla , Try a measure likethis for current inventory

 

Measure =
VAR __id = MAX ('Warehouse History'[Location] )
VAR __date = CALCULATE ( MAX('Warehouse History'[Date] ), ALLSELECTED ('Warehouse History' ), 'Warehouse History'[Location] = __id )
CALCULATE ( SUM('Warehouse History'[Value]), VALUES ('Table'[Location] ),'Warehouse History'[Location] = __id,'Warehouse History'[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.