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

DAX: calculate values based on last date by group

Hi guys, can you help me with this? Im having issues calculating the last date by group of data

 

Let's say I have this table:

RegionBankTypeDateValue
NABank1A1/1/201790
NABank1A1/12/201730
NABank1B3/4/201740
NABank1B2/2/201820
NABank2A1/1/201750
NABank2A1/4/201760
SABank1B1/1/201790
SABank1B4/1/201720
SABank1B4/16/201710
SABank1C1/1/201760
SABank3A1/1/201750
SABank3A3/15/201770
EUBank4D1/1/201740
EUBank4D1/1/20180

 

Basically want I'm trying to get is the value by lastest date by group. So my logic was:

1. Create new measure for LastDate

2. Create new measure to filter data only if it is last date

 

The idea is to finally have something like this:

RegionBankTypeDateValueLastDateLastValue
NABank1A1/1/2017901/12/2017 
NABank1A1/12/2017301/12/201730
NABank1B3/4/2017402/2/2018 
NABank1B2/2/2018202/2/201820
NABank2A1/1/2017501/4/2017 
NABank2A1/4/2017601/4/201760
SABank1B1/1/2017904/16/2017 
SABank1B4/1/2017204/16/2017 
SABank1B4/16/2017104/16/201710
SABank1C1/1/2017601/1/201760
SABank3A1/1/2017503/15/2017 
SABank3A3/15/2017703/15/201770
EUBank4D1/1/2017401/1/2018 
EUBank4D1/1/201801/1/20180

 

In order to show this:

NABank1A1/12/2017301/12/201730
NABank1B2/2/2018202/2/201820
NABank2A1/4/2017601/4/201760
SABank1B4/16/2017104/16/201710
SABank1C1/1/2017601/1/201760
SABank3A3/15/2017703/15/201770
EUBank4D1/1/201801/1/20180

 

Is the logic ok? Can you help me to calculate LastData and LastValue measures? Thanks!

1 ACCEPTED SOLUTION
PattemManohar
Community Champion
Community Champion

@Anonymous I guess you are looking for something like this...

 

Step 1 : Create an Index field in "Power Query Editor"

Step 2 : Create a Rnk field as below

 

Rnk = RANKX(FILTER(Test128LastVal,Test128LastVal[Region]=EARLIER(Test128LastVal[Region]) && Test128LastVal[Bank] = EARLIER(Test128LastVal[Bank]) && Test128LastVal[Type] = EARLIER(Test128LastVal[Type])),Test128LastVal[Index],,ASC,Dense)

Step 3 : Create an another RnkCheck as below

 

RnkCheck = CALCULATE(MAX(Test128LastVal[Rnk]),FILTER(ALL(Test128LastVal),Test128LastVal[Region]=EARLIER(Test128LastVal[Region]) && Test128LastVal[Bank] = EARLIER(Test128LastVal[Bank]) && Test128LastVal[Type] = EARLIER(Test128LastVal[Type])))

Step 4 : Finally, create a new table as below

 

Test128Out = FILTER(Test128LastVal,Test128LastVal[Rnk]=Test128LastVal[RnkCheck])

image.png

 





Did I answer your question? Mark my post as a solution!

Proud to be a PBI Community Champion




View solution in original post

4 REPLIES 4
PattemManohar
Community Champion
Community Champion

@Anonymous I guess you are looking for something like this...

 

Step 1 : Create an Index field in "Power Query Editor"

Step 2 : Create a Rnk field as below

 

Rnk = RANKX(FILTER(Test128LastVal,Test128LastVal[Region]=EARLIER(Test128LastVal[Region]) && Test128LastVal[Bank] = EARLIER(Test128LastVal[Bank]) && Test128LastVal[Type] = EARLIER(Test128LastVal[Type])),Test128LastVal[Index],,ASC,Dense)

Step 3 : Create an another RnkCheck as below

 

RnkCheck = CALCULATE(MAX(Test128LastVal[Rnk]),FILTER(ALL(Test128LastVal),Test128LastVal[Region]=EARLIER(Test128LastVal[Region]) && Test128LastVal[Bank] = EARLIER(Test128LastVal[Bank]) && Test128LastVal[Type] = EARLIER(Test128LastVal[Type])))

Step 4 : Finally, create a new table as below

 

Test128Out = FILTER(Test128LastVal,Test128LastVal[Rnk]=Test128LastVal[RnkCheck])

image.png

 





Did I answer your question? Mark my post as a solution!

Proud to be a PBI Community Champion




Anonymous
Not applicable

use a measure and a Calendar Table 

 

First Make a new table 

 

Calendar= CALENDAR(MIN(Table[Date),Max(Table[Date])

 

Create a relationships and then make the measure 

 

LastValue=Calculate(Sum(Value),LastDate(calendar'Dates) ) 

parry2k
Super User
Super User

@Anonymous wht you mean last date/value by group? What is group?



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Anonymous
Not applicable

Yeah title is wrong, I mean last date by group. And group = set of data with same Region/Bank/Type

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.