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
Anonymous
Not applicable

How get the last value on a given date

Hi all. 
I have  table: 

11.png

that false.  Would like to see the remainder from 12885,82625 as of 04.12.2019
More samples as I want to see:

3333.png2222.png

I try next queries, but nothing correct worked:
Remainder:=
var a = CALCULATE(LASTNONBLANK('Table1'[RemDoc], 1),
FILTER(ALL('Date'),'Date'[DateKey] <= MAX('Table1'[DateKey])))
var b = IF((a<=0),0)
return a
******


Remainder:=
var suma = CALCULATE (SUM('Table1'[RemDoc]),
FILTER (ALL('Date'),'Date'[DateKey] <= MAX('Table1'[DateKey])))
var rem = IF((suma<0),0,suma)
return rem

******

Остаток:=
SUMX (VALUES ('Table1'[Partner]),
VAR LastBalanceDate = CALCULATE ( MAX ( Table1'[DateKey] ) )
RETURN
CALCULATE (
SUM ('Table1'[RemDoc]),
'Date'[DateKey] >= LastBalanceDate))
****
How to achieve the desired result?
Thanks for your helps.

11 REPLIES 11
V-pazhen-msft
Community Support
Community Support

@Anonymous 
What you have tried is running total, to return latest date value, try create this measure using lastdate():

Measure = CALCULATE(SUM('Table1'[RemDoc]),LASTDATE('Table1'[Date]))
 
Paul Zheng _ Community Support Team
If this post helps, please Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

@V-pazhen-msft 

can't calculate the lastdate()

@Anonymous 

What do you mean you can't? Is there any error message?

You use calcuate() to call out the [Remdoc] column value, and filter to the lastdate of the given date.

 

Paul 

 

 

Anonymous
Not applicable

@V-pazhen-msft  can you help me?

Anonymous
Not applicable

@V-pazhen-msft 

Yes, error. Did as in your exemple.

lbendlin
Super User
Super User

remember you need to control the filter context for Calculate(), otherwise it will only calculate it for the "current row"

Anonymous
Not applicable

@lbendlin can you show an example?

lbendlin
Super User
Super User

Don't use functions inside CALCULATE() filters. They get impacted by the context transition. Define your filters as variables before using them in CALCULATE().

Anonymous
Not applicable

@lbendlin how to do it? Define filters as variable

Like you do it in your last example.

Anonymous
Not applicable

@lbendlin  
So:
VAR LastBalanceDate = CALCULATE(MAX( 'Table1'[DateKey]))
RETURN
CALCULATE(
LASTNONBLANK('Table1[RemDoc],SUM('Table1'[RemDoc])),
'Date'[DateKey] <= LastBalanceDate)

Or so:
LASTNONBLANK(VALUES ('Table1'[RemDoc]),
VAR LastBalanceDate = CALCULATE(MAX( 'Table1'[DateKey]))
RETURN
CALCULATE(
SUM ('Table1'[RemDoc]),
'Date'[DateKey] <= LastBalanceDate))

both options don't work

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.

Top Solution Authors
Top Kudoed Authors