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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Calculate Avg for selected Date, take value from last 3 days if a value is missing for today.

Hi All,

I have been struggling to build this measure, If [Occupancy %] is Blank for Select Date (21/11/2021) , then look into last three Dates, If [Occupancy %] exists in Last Three Dates then take into Calculation.  

Average(95%, 75%, 88%) for 21/11/2021 is 86% . 

AREADateOccupancy %
A21/11/202195%
B21/11/2021 
C21/11/202175%
D21/11/2021 
E21/11/2021 88%
A20/11/202197%
B20/11/2021  
C20/11/202194%
D20/11/2021 92%
E20/11/2021 100%
A19/11/202197%
B19/11/2021 
C19/11/202180%
D19/11/2021 96%
E19/11/202190%
A18/11/2021100%
B18/11/202162%
C18/11/202163%
D18/11/202189%
E18/11/202198%
A17/11/202182%
B17/11/202188%
C17/11/202164%
D17/11/202171%
E17/11/2021 97%

 

Desired Output for Date 21/11/2021:

Average(95%,  62%, 75%, 92%, 88%)  = 82% 

 

B and D are blank for 21/11/2021, so i have to take from previous available dates.

 

Thanks in Advance..

 

 

 

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@Anonymous , use a date table

 

Last Day Non Continuous =
var _1 = calculate(max(Table[Date]) , filter(allselected(Table), [AREA] = max(Table[AREA]) && 'Table'[Date] < max('Date'[Date])))
return
if(isblank([sales]) , calculate(sales, filter(all('Date'), 'Date' =_1)), [sales])

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

3 REPLIES 3
amitchandak
Super User
Super User

@Anonymous , use a date table

 

Last Day Non Continuous =
var _1 = calculate(max(Table[Date]) , filter(allselected(Table), [AREA] = max(Table[AREA]) && 'Table'[Date] < max('Date'[Date])))
return
if(isblank([sales]) , calculate(sales, filter(all('Date'), 'Date' =_1)), [sales])

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
amitchandak
Super User
Super User

@Anonymous , Trya measure like below, with help from date table

Rolling 3 = if(isblank([Occupancy %]), CALCULATE(AverageX(values('Date'[Date]),[Occupancy %]),DATESINPERIOD('Date'[Date ],MAX('Date'[Date])-1,-3,DAY)) ,[Occupancy %])

 

To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :radacad sqlbi My Video Series Appreciate your Kudos.

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

@amitchandak 

Thanks for replying, 

 

I dont want to calculate rolling,
I want to calculate the Average [Occupancy %] for Selected [Date] ,

But if [Occupancy %] is blank for Any [AREA] in the selected [Date] ,
then take previous Date [Occupancy %] to calculate the Average for Selected Date. 

 

You can see in the Data that [AREA] B and D are blank for the Date 21/11/2021, in this case i need to take 

[Occupancy %] for AREA B and D from previous Date 20/11/2021, or from 19/11/2021.

 

Thanks

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors