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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
knajar
Regular Visitor

Filter for largest week for the most recent Year

Hello,

 

I am trying to create a measure which I can use to filer to create a table that only includes rows for the latest(largest) week for the most recent year. 

For example, the correct output below should be the first three rows having latest week column as 1 and the rest as 0.

 

knajar_2-1645888891185.png

 

 

The calculated column is what outputs using the following code:

 

Latest Week =
VAR LatestYR =
CALCULATE ( MAX ( 'Weekly Estimating Lead-Time Report'[Year] ), ALL ( 'Weekly Estimating Lead-Time Report') )
VAR LatestWK =
CALCULATE ( MAX ( 'Weekly Estimating Lead-Time Report'[Week No.] ), FILTER('Weekly Estimating Lead-Time Report','Weekly Estimating Lead-Time Report'[Year]=LatestYR))

RETURN
IF ( MIN('Weekly Estimating Lead-Time Report'[Week No.])= LatestWK , 1, 0 )

 

Thank you very much for your help.


1 ACCEPTED SOLUTION

7 REPLIES 7
Whitewater100
Solution Sage
Solution Sage

Hi:

The other members are giving you a table for the records for the latest week. What are you missing?

The measure for latest week could be
Latest Week = 
var WeekNo = SELECTEDVALUE(Dates[Week No])
 return
IF(WeekNo =MAX(Dates[Week No], 1, "-")
 

This is another table function to give you the same type of table:

Calc Tble = CALCULATETABLE('YourTable',
Dates[Year]= MAX(Dates[Year]) &&
Dates[Week of Year] = MAX(Dates[Week No.])
 
The measure for latest week could be
Latest Week = 
var WeekNo = SELECTEDVALUE(Dates[Week No])
 return
IF(WeekNo =MAX(Dates[Week No], 1, "-")
 

@Whitewater100 right???  I provided the DAX and a screen snip showing exactly the intended outcome...

littlemojopuppy
Community Champion
Community Champion

Hi @knajar 

 

This will create a table that contains the only the records for the top week in the most recent year

 

Calculated Table = 
VAR	MostRecentYear =
	CALCULATE(
		MAX(RawData[Year]),
		ALL(RawData)
	)
VAR	LargestWeek =
	TOPN(
		1,
		FILTER(
			ALL(RawData),
			RawData[Year] = MostRecentYear
		),
		RawData[WeekNumber],
		DESC
	)
RETURN

LargestWeek

 

littlemojopuppy_0-1645980216098.png

 

Hope this helps!

Hello,

 

Thank you for the reply. When I tried this solution I get the following error:

"The expression refers to multiple columns. Multiple columns cannot be converted to a scalar value."

@knajar how's this look?

Thank you very much for the response. It worked.

@knajar glad I could help!

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.