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
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
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