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
Marius
New Member

Get Value assigned to last entry each month

Hi,

 

I'm fairly new to Power BI and probably this is much easier than I make it. But I just can't get my brain to work through the problem.

 

I have a Table:

IDDateValue
101/01/2021$1000
201/01/2021$1100
301/01/2021$1500
402/01/2021$2800
502/01/2021$2500
615/02/2021$1500
715/02/2021$1400
818/02/2021$1700
927/02/2021$1000

 

Now I want to show in a Visual always the value for the last row of each day and in another for each month or both together in a matrix.

The list is sorted before the import. So the highest ID of each Day/Month is also automatically the last entry. Maybe this helps.

 

I tried taking the "MAX ID" and put it into a matrix. But then I don't know how to obtain the related value to this MAX ID.

 

As I said, probably it is very easy and I just can't see it.

2 ACCEPTED SOLUTIONS
stevedep
Memorable Member
Memorable Member

Hi,

Its possible to do it like this:

LastVal = 
CALCULATE(SUM('Table'[Value]), LASTNONBLANK(DimDate[Date].[Date], CALCULATE(SUM('Table'[Value]))))

As seen here:

stevedep_0-1614920195628.png

File is attached.

Kind regards, Steve. 

 

View solution in original post

Thanks, did not worked out for me on first try. Something is adding up to much. But I need to serach for the error in my Data model I guess. For now, with the hind of using "lookupvalue" I was able to solve the problem very easily as well.

LookupTest = LOOKUPVALUE('FACT - Table'[Value],'FACT - Table'[Value ID], MAX('FACT - Table'[Value ID]))

View solution in original post

4 REPLIES 4
stevedep
Memorable Member
Memorable Member

Hi,

Its possible to do it like this:

LastVal = 
CALCULATE(SUM('Table'[Value]), LASTNONBLANK(DimDate[Date].[Date], CALCULATE(SUM('Table'[Value]))))

As seen here:

stevedep_0-1614920195628.png

File is attached.

Kind regards, Steve. 

 

Thanks, did not worked out for me on first try. Something is adding up to much. But I need to serach for the error in my Data model I guess. For now, with the hind of using "lookupvalue" I was able to solve the problem very easily as well.

LookupTest = LOOKUPVALUE('FACT - Table'[Value],'FACT - Table'[Value ID], MAX('FACT - Table'[Value ID]))
rfigtree
Resolver III
Resolver III

hopefully i didnt make a mistake in the syntax but here you go.

lastForDay= 
var _ID=calculate(max(table[id]),filter(all(table),table[date]=earlier(table[date])) 
return lookupvalue(table[value],table[id],_ID)

lastForDayYear= 
var _ID=calculate(max(table[id]),filter(all(table),Year(table[date])=Year(earlier(table[date]))) 
return lookupvalue(table[value],table[id],_ID)

 

Hi,

thanks, but I get an error on this.

EARLIER/EARLIEST refers to an earlier row context which doesn't exist.

 

My code with real table,colum names:

LastEntry = var _ID= CALCULATE(max('FACT - Saldo'[Saldo ID]), FILTER(ALL('FACT - Saldo'), 'FACT - Saldo'[Date] =EARLIER('FACT - Saldo'[Date])))
return LOOKUPVALUE('FACT - Saldo'[SALDO],'FACT - Saldo'[Saldo ID], _ID)

 

When I come to the "Earlier" part, it already does not show the dropdown to select my column. I just wrote it in by hand.

I don't understand the earlier funtion either. The Help article of it is complex as well...

 

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