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:

2222.png3333.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.

 

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

Hi @Anonymous 

I think you can add an index column in Power Query Editor.

My Sample:

1.png

Group all rows by DateKey column, then add an index column by custom column.

2.png

Expand all column in Custom and remove other columns.

3.png

Build a calendar table for slicer.

Calendar = CALENDARAUTO()

Then build a measure filter and Remainder measure.

Filter = IF(MAX('Table'[DatePay])<=SELECTEDVALUE('Calendar'[Date]),1,0)
Remainder = 
VAR _MaxDate = MAXX(FILTER(ALL('Table'),'Table'[Partner]=MAX('Table'[Partner])&&'Table'[DatePay]<=SELECTEDVALUE('Calendar'[Date])),'Table'[DatePay])
VAR _MaxIndex = MAXX(FILTER(ALL('Table'),'Table'[Partner]=MAX('Table'[Partner])&&'Table'[DatePay] = _MaxDate),'Table'[Rank])
RETURN
IF(HASONEVALUE('Table'[DateKey]),SUM('Table'[RemDoc]),SUMX(FILTER(ALL('Table'),'Table'[Partner]=MAX('Table'[Partner])&&'Table'[DatePay] = _MaxDate&&'Table'[Rank]=_MaxIndex),'Table'[RemDoc]))

Result is as below.

4.png

You can download the pbix file from this link: File

 

Best Regards,

Rico Zhou

 

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

3 REPLIES 3
v-rzhou-msft
Community Support
Community Support

Hi @Anonymous 

I think you can add an index column in Power Query Editor.

My Sample:

1.png

Group all rows by DateKey column, then add an index column by custom column.

2.png

Expand all column in Custom and remove other columns.

3.png

Build a calendar table for slicer.

Calendar = CALENDARAUTO()

Then build a measure filter and Remainder measure.

Filter = IF(MAX('Table'[DatePay])<=SELECTEDVALUE('Calendar'[Date]),1,0)
Remainder = 
VAR _MaxDate = MAXX(FILTER(ALL('Table'),'Table'[Partner]=MAX('Table'[Partner])&&'Table'[DatePay]<=SELECTEDVALUE('Calendar'[Date])),'Table'[DatePay])
VAR _MaxIndex = MAXX(FILTER(ALL('Table'),'Table'[Partner]=MAX('Table'[Partner])&&'Table'[DatePay] = _MaxDate),'Table'[Rank])
RETURN
IF(HASONEVALUE('Table'[DateKey]),SUM('Table'[RemDoc]),SUMX(FILTER(ALL('Table'),'Table'[Partner]=MAX('Table'[Partner])&&'Table'[DatePay] = _MaxDate&&'Table'[Rank]=_MaxIndex),'Table'[RemDoc]))

Result is as below.

4.png

You can download the pbix file from this link: File

 

Best Regards,

Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. 

Greg_Deckler
Super User
Super User

@Anonymous - Do you have any other indicator like an Index column to denote the "latest"?


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

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