Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
blairtj
Regular Visitor

Is there a better way to get lastest row up to a given date qualified by another column

Hi all,

 

I have a solution to this problem but it seems clunky to me. I can't think of a better way of doing it with the data as is however, so looking for suggestions.

 

I have lookup table with dates and the work level (full time = 100%, half time = 50%, etc.) that team members were working on the team by date. Whenever the work level of a member changed there would be a new row with effective date of the change, the member's name, and the new work level.

 

I'm trying to find a way to look up the work level on a given date for a given team member.

 

The table is as follows and you can grab the pbix here.

 

DateNameWork Level
2018-01-01Ron0%
2018-01-01Trisha100%
2018-01-01Sam100%
2018-01-01Vanessa80%
2018-01-01Brandon100%
2018-01-01Sarah0%
2018-01-01Penelope50%
2018-01-01Jim100%
2018-01-01Rodger100%
2018-05-01Penelope100%
2018-04-05Sarah100%
2018-03-19Brandon0%
2018-10-02Brandon100%
2018-10-30Penelope0%
2020-01-24Sarah0%

 

My solution here is hardcoded for Penelope. I'll need to look up each team member on a given date so can't rely on filter context to narrow the table down to a given team member. The approach is to save a table with only rows for the selected team member. Then get the last date from the table, and then finally lookup the work level in the temp table from the table based on the date determined in the previous step.

 

The reason the active_date was a separate step was that I could not figure out a way to use LASTDATE on the temp table in the same calculate statement that did the lookup. Power BI kept complaining of the syntax, table not found etc. I tried empty table name ('') explicit table/column references but couldn't find another combination that worked.

 

So the following works, but as I say, seems very clunky. I would appreciate any suggestions to improve this.

 

 

 

Penelope Work Level = 
	var effective_date = LASTDATE('Work Levels'[Date])
	
	var data1 = 
		FILTER(
			'Work Levels',
			'Work Levels'[Name]="Penelope" && 'Work Levels'[Date] <= effective_date
		)
		
		
	var active_date =
		CALCULATE(
			LASTDATE('Work Levels'[Date]),
			data1
		)
		
	return
		CALCULATE(
            MAX('Work Levels'[Work Level]),
            FILTER(
			    data1,
			    [Date] = active_date
            )
        )

 

 

 

Cheers,

Blair

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

Hi @blairtj 

 

Kindly check the attachment. let me know if you have any further requirements.

 

Community Support Team _ Dina Ye
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

4 REPLIES 4
v-diye-msft
Community Support
Community Support

Hi @blairtj 

 

Kindly check the attachment. let me know if you have any further requirements.

 

Community Support Team _ Dina Ye
If this post helps, then please consider Accept it as the solution to help the other members find it more
quickly.

Hi @v-diye-msft,

Thank you for this. It does indeed work and seems much simpler. I was avoiding filtering by name first and now I'm not totally sure why. I have to think about this.

Greg_Deckler
Super User
Super User

Not sure I followed all of that completely but is *seems* like a lookup min/max sort of problem. https://community.powerbi.com/t5/Quick-Measures-Gallery/Lookup-Min-Max/m-p/985814#M434


Follow on LinkedIn
@ 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...

Hi @Greg_Deckler , Thanks for your link. I need to work through the pattern you referred me to as I haven't yet familiarized myself with Summarize.

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.