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.
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:
Region | Bank | Type | Date | Value |
NA | Bank1 | A | 1/1/2017 | 90 |
NA | Bank1 | A | 1/12/2017 | 30 |
NA | Bank1 | B | 3/4/2017 | 40 |
NA | Bank1 | B | 2/2/2018 | 20 |
NA | Bank2 | A | 1/1/2017 | 50 |
NA | Bank2 | A | 1/4/2017 | 60 |
SA | Bank1 | B | 1/1/2017 | 90 |
SA | Bank1 | B | 4/1/2017 | 20 |
SA | Bank1 | B | 4/16/2017 | 10 |
SA | Bank1 | C | 1/1/2017 | 60 |
SA | Bank3 | A | 1/1/2017 | 50 |
SA | Bank3 | A | 3/15/2017 | 70 |
EU | Bank4 | D | 1/1/2017 | 40 |
EU | Bank4 | D | 1/1/2018 | 0 |
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:
Region | Bank | Type | Date | Value | LastDate | LastValue |
NA | Bank1 | A | 1/1/2017 | 90 | 1/12/2017 | |
NA | Bank1 | A | 1/12/2017 | 30 | 1/12/2017 | 30 |
NA | Bank1 | B | 3/4/2017 | 40 | 2/2/2018 | |
NA | Bank1 | B | 2/2/2018 | 20 | 2/2/2018 | 20 |
NA | Bank2 | A | 1/1/2017 | 50 | 1/4/2017 | |
NA | Bank2 | A | 1/4/2017 | 60 | 1/4/2017 | 60 |
SA | Bank1 | B | 1/1/2017 | 90 | 4/16/2017 | |
SA | Bank1 | B | 4/1/2017 | 20 | 4/16/2017 | |
SA | Bank1 | B | 4/16/2017 | 10 | 4/16/2017 | 10 |
SA | Bank1 | C | 1/1/2017 | 60 | 1/1/2017 | 60 |
SA | Bank3 | A | 1/1/2017 | 50 | 3/15/2017 | |
SA | Bank3 | A | 3/15/2017 | 70 | 3/15/2017 | 70 |
EU | Bank4 | D | 1/1/2017 | 40 | 1/1/2018 | |
EU | Bank4 | D | 1/1/2018 | 0 | 1/1/2018 | 0 |
In order to show this:
NA | Bank1 | A | 1/12/2017 | 30 | 1/12/2017 | 30 |
NA | Bank1 | B | 2/2/2018 | 20 | 2/2/2018 | 20 |
NA | Bank2 | A | 1/4/2017 | 60 | 1/4/2017 | 60 |
SA | Bank1 | B | 4/16/2017 | 10 | 4/16/2017 | 10 |
SA | Bank1 | C | 1/1/2017 | 60 | 1/1/2017 | 60 |
SA | Bank3 | A | 3/15/2017 | 70 | 3/15/2017 | 70 |
EU | Bank4 | D | 1/1/2018 | 0 | 1/1/2018 | 0 |
Is the logic ok? Can you help me to calculate LastData and LastValue measures? Thanks!
Solved! Go to Solution.
@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])
Proud to be a PBI 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])
Proud to be a PBI Community Champion
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) )
@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.
Yeah title is wrong, I mean last date by group. And group = set of data with same Region/Bank/Type
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
114 | |
99 | |
82 | |
70 | |
61 |
User | Count |
---|---|
149 | |
114 | |
107 | |
89 | |
67 |