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
Brycert
Resolver I
Resolver I

Measure rendering as blank in Calculate

Greetings all, hopefully you can help me with this one:

 

I have this measure:

 

Count of Claims Previous Week_1:= VAR CurrentWeek = SELECTEDVALUE('Claim_LastUpdate'[WeekOfYear])
VAR CurrentYear = SELECTEDVALUE('Claim_LastUpdate'[Year])
VAR MaxWeekNumber = CALCULATE(MAX('Claim_LastUpdate'[WeekOfYear]),ALL(Claim_LastUpdate),'Claim_LastUpdate'[Year]=CurrentYear-1)


VAR BeginPrevWeekValue= CALCULATE(MIN('Claim_LastUpdate'[FirstofWeek]),ALL(Claim_LastUpdate), 'Claim_LastUpdate'[WeekOfYear] = (CurrentWeek -1) && Claim_LastUpdate[Year] = CurrentYear )
VAR EndPrevWeekValue= CALCULATE(MAX('Claim_LastUpdate'[LastofWeek]),ALL(Claim_LastUpdate), 'Claim_LastUpdate'[WeekOfYear] = (CurrentWeek -1) && Claim_LastUpdate[Year] = CurrentYear )

var result =
IF(CurrentWeek <> 2,
CALCULATE('Claim_Measures'[Count of Claims],FILTER(ALL(Claim_LastUpdate),IF(CurrentWeek=1,Claim_LastUpdate[WeekOfYear]=MaxWeekNumber && Claim_LastUpdate[Year]=CurrentYear-1,Claim_LastUpdate[WeekOfYear] = CurrentWeek - 1 && Claim_LastUpdate[Year]=CurrentYear) )
), IF(CurrentWeek= 2, CALCULATE('Claim_Measures'[Count of Claims],Claim_LastUpdate[FirstOfWeek]=BeginPrevWeekValue && Claim_LastUpdate[LastOfWeek]=EndPrevWeekValue && Claim_LastUpdate[Year] = CurrentYear && 'Claim_LastUpdate'[WeekOfYear] = (CurrentWeek -1) ))
)

return result

 

The reason I am making the distinction with (CurrentWeek=2) is that my calendar table contains only one row for Week 1 of 2019, however there are begin and start dates for this week within this row so I am accomodating that eventuality in retrieving the FirstofWeek and EndofWeek dates in order to calculate 'Claim_Measures'[Count of Claims]. However when rendering in PowerBI, I am getting this:

 

Brycert_0-1642609871008.png

Obviously I should be getting "32" for "Count of Claims Previous Week_1" measure. When I put the particular calculate expression in DAX studio: i.e.

 

EVALUATE
{

CALCULATE('Claim_Measures'[Count of Claims],Claim_LastUpdate[FirstOfWeek]= DATE(2018,12,30) && Claim_LastUpdate[LastOfWeek]=DATE(2019,1,5) && Claim_LastUpdate[Year] = 2019 && 'Claim_LastUpdate'[WeekOfYear] = 1)
}

 

I get the correct results:

 

Brycert_1-1642610008894.png

 

Any idea whats going on here? Could it be that the BeginPrevWeekValue and EndPrevWeekValue are including the time also? When rendering the expression for these variables in DAX studio, I do see a date time like here:

 

 

EVALUATE
{

CALCULATE(VALUES('Claim_LastUpdate'[FirstofWeek]), 'Claim_LastUpdate'[WeekOfYear] = (1) && Claim_LastUpdate[Year] = 2019 )

}

 

Brycert_2-1642610156272.png

Thanks in advance for any help!

 

 

1 ACCEPTED SOLUTION
Brycert
Resolver I
Resolver I

Found the issue, the measure should be:

 

Count of Claims Previous Week_1:= VAR CurrentWeek = SELECTEDVALUE('Claim_LastUpdate'[WeekOfYear]) VAR CurrentYear = SELECTEDVALUE('Claim_LastUpdate'[Year]) VAR MaxWeekNumber = CALCULATE(MAX('Claim_LastUpdate'[WeekOfYear]),ALL(Claim_LastUpdate),'Claim_LastUpdate'[Year]=CurrentYear-1) VAR BeginPrevWeekValue= CALCULATE(MIN('Claim_LastUpdate'[FirstofWeek]),ALL(Claim_LastUpdate), 'Claim_LastUpdate'[WeekOfYear] = (CurrentWeek -1) && Claim_LastUpdate[Year] = CurrentYear ) VAR EndPrevWeekValue= CALCULATE(MAX('Claim_LastUpdate'[LastofWeek]),ALL(Claim_LastUpdate), 'Claim_LastUpdate'[WeekOfYear] = (CurrentWeek -1) && Claim_LastUpdate[Year] = CurrentYear ) var result = IF(CurrentWeek <> 2, CALCULATE('Claim_Measures'[Count of Claims],FILTER(ALL(Claim_LastUpdate),IF(CurrentWeek=1,Claim_LastUpdate[WeekOfYear]=MaxWeekNumber && Claim_LastUpdate[Year]=CurrentYear-1,Claim_LastUpdate[WeekOfYear] = CurrentWeek - 1 && Claim_LastUpdate[Year]=CurrentYear) ) ), IF(CurrentWeek= 2, CALCULATE('Claim_Measures'[Count of Claims],ALL(Claim_LastUpdate),Claim_LastUpdate[FirstOfWeek]=BeginPrevWeekValue && Claim_LastUpdate[LastOfWeek]=EndPrevWeekValue && Claim_LastUpdate[Year] = CurrentYear && 'Claim_LastUpdate'[WeekOfYear] = (CurrentWeek -1) )) ) return result

View solution in original post

1 REPLY 1
Brycert
Resolver I
Resolver I

Found the issue, the measure should be:

 

Count of Claims Previous Week_1:= VAR CurrentWeek = SELECTEDVALUE('Claim_LastUpdate'[WeekOfYear]) VAR CurrentYear = SELECTEDVALUE('Claim_LastUpdate'[Year]) VAR MaxWeekNumber = CALCULATE(MAX('Claim_LastUpdate'[WeekOfYear]),ALL(Claim_LastUpdate),'Claim_LastUpdate'[Year]=CurrentYear-1) VAR BeginPrevWeekValue= CALCULATE(MIN('Claim_LastUpdate'[FirstofWeek]),ALL(Claim_LastUpdate), 'Claim_LastUpdate'[WeekOfYear] = (CurrentWeek -1) && Claim_LastUpdate[Year] = CurrentYear ) VAR EndPrevWeekValue= CALCULATE(MAX('Claim_LastUpdate'[LastofWeek]),ALL(Claim_LastUpdate), 'Claim_LastUpdate'[WeekOfYear] = (CurrentWeek -1) && Claim_LastUpdate[Year] = CurrentYear ) var result = IF(CurrentWeek <> 2, CALCULATE('Claim_Measures'[Count of Claims],FILTER(ALL(Claim_LastUpdate),IF(CurrentWeek=1,Claim_LastUpdate[WeekOfYear]=MaxWeekNumber && Claim_LastUpdate[Year]=CurrentYear-1,Claim_LastUpdate[WeekOfYear] = CurrentWeek - 1 && Claim_LastUpdate[Year]=CurrentYear) ) ), IF(CurrentWeek= 2, CALCULATE('Claim_Measures'[Count of Claims],ALL(Claim_LastUpdate),Claim_LastUpdate[FirstOfWeek]=BeginPrevWeekValue && Claim_LastUpdate[LastOfWeek]=EndPrevWeekValue && Claim_LastUpdate[Year] = CurrentYear && 'Claim_LastUpdate'[WeekOfYear] = (CurrentWeek -1) )) ) return result

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.