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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
glennkobes
New Member

repost: Wine Inventory

Hi, This is a repost as I have not yet found a solution. Orignal post.  

I also have the link to the file (here). My main issue is that I have a measure to get the latest date for which there is a "Set" entry. [Last Set Date In Context] returns 9/6/2017, which is what I expected. However, when I use that messure to return a running total, I do not get the expected result. 

 

=SUMX(
WineList,
CALCULATE(
sum(WineLog[Bottles])*-1,
WineLog[Transaction Type] = "Take",
filter(all( 'Calendar'),'Calendar'[date] >= [Last Set Date In Context] )))

 

returns -7, which is not correct. However, if I hard code the date,

=SUMX(
WineList,
CALCULATE(
sum(WineLog[Bottles])*-1,
WineLogtt[Transaction Type] = "Take",
filter( 'Calendar','Calendar'[date] >= date(2017,09,06 ))))

This returns "-2", which is what I expect.

 

Any thoughts on what I am doing wrong?

 

1 ACCEPTED SOLUTION
themistoklis
Community Champion
Community Champion

@glennkobes 

 

Make sure you assign the date in 'Last Set Date In Context' field to a variable.

 

Then add the variable to the measure:

 

 

Measure =
VAR _Last_Set_Date_In_Context = MAX(WineLog[Bottles])

RETURN
SUMX(
WineList,
CALCULATE(
sum(WineLog[Bottles])*-1,
WineLogtt[Transaction Type] = "Take",
filter( 'Calendar','Calendar'[date] >= _Last_Set_Date_In_Context)))

 

 

View solution in original post

2 REPLIES 2
themistoklis
Community Champion
Community Champion

@glennkobes 

 

Make sure you assign the date in 'Last Set Date In Context' field to a variable.

 

Then add the variable to the measure:

 

 

Measure =
VAR _Last_Set_Date_In_Context = MAX(WineLog[Bottles])

RETURN
SUMX(
WineList,
CALCULATE(
sum(WineLog[Bottles])*-1,
WineLogtt[Transaction Type] = "Take",
filter( 'Calendar','Calendar'[date] >= _Last_Set_Date_In_Context)))

 

 

Thanks @themistoklis! This helped alot! I also discovered that I could use the Datesbetween function to get the proper date range. Below is the formula for the measure that returned the correct value. 

 

Thanks again for your help! 

 

=VAR _Last_Set_Date_In_Context = [Last Set Date In Context]
RETURN
SUMX(
WineList,
CALCULATE(
SUM( WineLog[Bottles] ) * -1,
WineLogtt[Transaction Type] = "Take",
DATESBETWEEN(
'Calendar'[Date],
_Last_Set_Date_In_Context,
MAX( 'Calendar'[Date] )
)
)
)

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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