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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
TriveniN
Helper II
Helper II

How to achive below looping logic in powerbi

Need Help on below requirement

Based on slicer selection

Example if user selects dates between 1/1/2023 to 01/31/2023

we need to calculate count of property's like below

for 01/01/2023  :

count(name), listing_start_date <mindate

and it should be divided by no.of days, here in this case no.of days is 1 

for 02/01/2023  :    listing_start_date <mindate+1

and it should be divided by no.of days, here in this case no.of days is 2

etc..... and we need to sum up all and show the result like below

 

Proprty_name     SUM_Value

Atlanta                 30

 

Any ideas would be largely appreciated. 

1 ACCEPTED SOLUTION

Something like this?

lbendlin_0-1682556046155.png

 

 

You can use averagex() instead of sumx() for the final result.

 

see attached.

View solution in original post

5 REPLIES 5
TriveniN
Helper II
Helper II

How to get occupency only for few properties 

 

Below is DAX to Calculate count of leases and it will return  468

VAR _SS_AvgOcc =
CALCULATE( DISTINCTCOUNT(LEASE_SFV[Name 1] ),
LEASE_SFV[Lease_Type__c] IN {"Initial"}
&&  
NOT LEASE_SFV[Yardi_Lease_Status__c] IN {"Canceled" , "pending"}
 ,
FILTER(ACQUIRED_PROPERTY_SFV,
(ACQUIRED_PROPERTY_SFV[Stabilization_Date__c] <> BLANK() &&  
ACQUIRED_PROPERTY_SFV[Stabilization_Date__c] <= _SSdate ) -- 
&& (ACQUIRED_PROPERTY_SFV[Disposition_Date__c] = BLANK() ||
ACQUIRED_PROPERTY_SFV[Disposition_Date__c] > _SSdate) )
)

I need to calculate occupency only for above properties(468). Below is the DAX to calculate occupency 

VAR _SS_AvgOcc_Quarter =
CALCULATE( IF(
MAXX(LEASE_SFV,LEASE_SFV[Move_Out_Date__c]) < _date  
&& VALUES(LEASE_SFV[Move_Out_Date__c])<> BLANK() ,
DATEDIFF( _dateQMIN , MAXX(LEASE_SFV,LEASE_SFV[Move_Out_Date__c]), DAY) ,
DATEDIFF( _dateQMIN , _dateQ +1, DAY)
),    
LEASE_SFV[Lease_Type__c] = "Initial" &&
NOT LEASE_SFV[Yardi_Lease_Status__c] IN {"Canceled" , "pending"}  
&&
 IF(SELECTEDVALUE(ReportPeriod[Type]) = "Month",
FORMAT(LEASE_SFV[Lease_Start_Date__c],"YYYYMM") <= FORMAT(_date,"YYYYMM"), --date
IF(SELECTEDVALUE(ReportPeriod[Type]) = "Quarter",
FORMAT(LEASE_SFV[Lease_Start_Date__c],"YYYYQ") <= FORMAT(_date,"YYYYQ")) )
&&
( LEASE_SFV[Move_Out_Date__c] = BLANK() ||
IF(SELECTEDVALUE(ReportPeriod[Type]) = "Month",
FORMAT(LEASE_SFV[Move_Out_Date__c],"YYYYMM") >= FORMAT(_dateMIN,"YYYYMM"),
 IF(SELECTEDVALUE(ReportPeriod[Type]) = "Quarter",
FORMAT(LEASE_SFV[Move_Out_Date__c],"YYYYQ") >= FORMAT(_dateMIN,"YYYYQ"))))
 ,
FILTER(ACQUIRED_PROPERTY_SFV,
(ACQUIRED_PROPERTY_SFV[Stabilization_Date__c] <> BLANK() &&  
ACQUIRED_PROPERTY_SFV[Stabilization_Date__c] <= _SSdate )
&& (ACQUIRED_PROPERTY_SFV[Disposition_Date__c] = BLANK() ||
ACQUIRED_PROPERTY_SFV[Disposition_Date__c] > _date) )
)

VAR _TPDIP =
IF( SELECTEDVALUE(ReportPeriod[Type])="Month",
  DATEDIFF(CALCULATE(STARTOFMONTH(Datecalendar[TheDate])), _dateM+1,DAY),
IF(SELECTEDVALUE(ReportPeriod[Type])="Quarter",
  DATEDIFF(CALCULATE(STARTOFQUARTER(Datecalendar[TheDate])), _dateQ+1, DAY)) )

VAR _SS_AvgOcc= IF(SELECTEDVALUE(ReportPeriod[Type]) = "Month",_SS_AvgOcc_Month,_SS_AvgOcc_Quarter)

RETURN
SWITCH( TRUE(),
SELECTEDVALUE(TotalProtfolio_Rows[Key]) = 1 && SELECTEDVALUE(ReportType[Key]) = 1 ,
 _TP_AvgOcc/_TPDIP,
SELECTEDVALUE(TotalProtfolio_Rows[Key]) = 1 && SELECTEDVALUE(ReportType[Key]) = 2
// && _SS_AvgOcc_Name <> BLANK()
,
_SS_AvgOcc/_TPDIP,
BLANK())

 

When we use Occupency DAX(above DAX)  , it is calculating occupency for 679 leases(Total leases 679)

 

How to calculate occupency only for those 468 leases?

 

Any ideas would be largely appreciated. 

Please provide sample data that covers your issue or question completely, in a usable format (not as a screenshot).
https://community.powerbi.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-Forum/ba-...
Please show the expected outcome based on the sample data you provided.

https://community.powerbi.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447523

lbendlin
Super User
Super User

Please provide sample data that covers your issue or question completely, in a usable format (not as a screenshot).
https://community.powerbi.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-Forum/ba-...
Please show the expected outcome based on the sample data you provided.

https://community.powerbi.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447523

Thanks for your response and below table is for sample data.

MSACountyLstStartDate__cLstEnd_Date__cMIR_End_Date__cMType__cMR_Start_Date__cYar_Date__c
JakClay9/21/202112/10/202110/19/2021Initial8/17/202112/17/2021
JakClay4/12/2023 4/12/2023Turn4/3/2023 
DalCollin     11/3/2021
DalCollin12/23/20213/7/202212/21/2021Initial11/8/20213/10/2022
DalCollin4/18/2023 4/24/2023Turn4/11/2023 
DalDenton12/20/20213/7/202212/16/2021Initial11/8/20213/13/2022
DalDenton4/19/2023 4/20/2023Turn4/18/2023 
AtlGwi12/27/20215/7/202212/24/2021Initial10/28/20215/20/2022
AtlGwi3/20/2023 3/24/2023Turn3/17/2023 
AtlGwi8/26/2022 8/26/2022Initial8/5/2022 
JakClay11/3/202111/12/202111/3/2021Initial9/27/202111/12/2021
JakClay3/31/20224/5/20223/30/2022Turn3/23/20224/8/2022
JakClay4/12/2023 4/18/2023Turn4/3/2023 
JakClay1/20/20221/27/20221/20/2022Initial11/9/20212/9/2022
JakClay2/23/2023 2/27/2023Turn2/20/2023 
AtlCobb10/4/202112/6/202110/1/2021Initial8/3/202112/10/2021
AtlCobb3/30/2023 4/4/2023Turn3/21/2023 
DalCollin9/29/202112/9/20219/28/2021Initial7/29/202112/15/2021
DalCollin3/22/2023 4/12/2023Turn3/20/2023 
DalCollin     3/14/2022
DalCollin4/20/20228/27/20225/13/2022Initial4/1/20228/31/2022
DalCollin4/18/2023 4/24/2023Turn4/10/2023 
DalDenton3/26/20214/17/20212/10/2021Initial1/25/20213/30/2021
DalDenton3/4/20223/23/20223/2/2022Turn1/27/20223/28/2022
DalDenton4/14/2023 4/19/2023Turn4/11/2023 
DalDenton7/22/202110/22/20217/21/2021Initial6/4/202110/30/2021
DalDenton4/19/2023 4/21/2023Turn4/14/2023 
JakDuval7/14/20219/27/20219/16/2021Initial6/21/20219/30/2021
JakDuval12/30/2022 1/20/2023Turn12/19/2022 
JakDuval1/10/20222/23/202212/30/2021Initial11/3/20212/26/2022
JakDuval3/10/2023 4/3/2023Turn3/3/2023 
DalEllis8/16/20218/26/20218/26/2021Initial7/9/20218/31/2021
DalEllis4/10/2023 4/16/2023Turn3/31/2023 
DalEllis     8/13/2021
DalEllis11/29/20212/11/202211/29/2021Initial9/7/20212/13/2022
DalEllis4/18/2023 4/25/2023Turn4/10/2023 
AtlGwi1/4/20222/14/202212/31/2021Initial8/19/20212/20/2022
AtlGwi2/23/2023 2/28/2023Turn2/20/2023 
ChrIredell1/31/20225/10/20221/29/2022Initial10/26/20215/12/2022
ChrIredell2/13/2023 2/23/2023Turn2/1/2023 
DalKaufman9/21/20211/6/20229/20/2021Initial7/2/20211/16/2022
DalKaufman3/3/2023 3/13/2023Turn2/14/2023 
JakSt. Johns3/25/20225/10/20223/24/2022Initial2/24/20225/15/2022
JakSt. Johns12/6/2022 12/13/2022Turn12/5/2022 
JakSt. Johns4/1/20225/9/20224/1/2022Initial2/22/20225/17/2022
JakSt. Johns3/14/2023 3/17/2023Turn3/13/2023 
DalTarrant4/22/20215/2/20214/20/2021Initial3/17/20215/12/2021
DalTarrant6/24/20226/29/20226/24/2022Turn6/1/20227/11/2022
DalTarrant4/10/2023 4/12/2023Turn4/4/2023 
DalDenton     5/9/2022
DalDenton12/8/2022 12/17/2022Initial11/30/2022 
AtlGwi12/5/2022 12/12/2022Initial11/17/2022 
ChrIredell9/18/2022 10/6/2022Initial9/9/2022 
ChrIredell10/13/2022 10/21/2022Initial10/3/2022 
DalKaufman9/6/202211/1/20229/8/2022Initial8/26/202211/3/2022
DalKaufman3/1/2023 3/8/2023Turn2/28/2023 
ChrMecklenburg5/13/20226/27/20225/31/2022Initial4/19/20226/29/2022
ChrMecklenburg11/11/2022 11/21/2022Turn11/3/2022 
JakSt. Johns9/30/202211/13/202210/14/2022Initial8/29/202211/14/2022
JakSt. Johns4/14/2023 4/18/2023Turn4/3/2023 
ChrUnion9/29/2022 10/6/2022Initial9/12/2022 
AtlForsyth1/1/20222/5/202212/29/2021Initial9/27/20212/10/2022
AtlForsyth4/18/2023 4/25/2023Turn4/10/2023 
AtlForsyth     9/9/2021
AtlForsyth2/4/20222/10/20222/2/2022Initial9/28/20212/16/2022
AtlForsyth2/27/2023 3/6/2023Turn2/22/2023 
JakNassau12/17/20214/25/202212/15/2021Initial10/14/20214/27/2022
JakNassau3/21/2023 3/22/2023Turn3/15/2023 
JakSt. Johns6/2/20229/12/20226/6/2022Initial5/25/20229/21/2022
JakSt. Johns3/20/2023 3/24/2023Turn3/16/2023 
ChrCabarrus2/28/20226/6/20222/23/2022Initial11/20/20216/7/2022
ChrCabarrus4/14/2023 4/24/2023Turn4/9/2023 
DalEllis     11/30/2021
DalEllis2/11/20223/7/20222/10/2022Initial12/29/20213/15/2022
DalEllis11/9/202212/14/202211/9/2022Turn11/2/202212/19/2022
DalEllis3/8/2023 3/13/2023Turn3/6/2023 
ChrGaston     7/5/2022
ChrGaston8/9/20229/16/20228/20/2022Initial8/2/20229/20/2022
ChrGaston4/3/2023 4/6/2023Turn4/1/2023 
AtlGwi7/22/20229/18/20227/29/2022Initial6/23/20229/22/2022
AtlGwi3/3/2023 3/9/2023Turn2/28/2023 
ChrIredell10/14/20214/5/20221/8/2022Initial9/20/20214/5/2022
ChrIredell4/18/2023 4/22/2023Turn4/10/2023 
ChrIredell4/12/20224/29/20224/11/2022Initial3/21/20225/3/2022
ChrIredell11/30/2022 12/14/2022Turn11/29/2022 
ChrLincoln     4/25/2022
ChrLincoln7/1/20227/26/20227/19/2022Initial6/9/20227/28/2022
ChrLincoln1/3/2023 1/6/2023Turn12/27/2022 
DalRockwall12/28/20213/28/202212/23/2021Initial11/10/20214/1/2022
DalRockwall4/18/2023 4/19/2023Turn4/13/2023 

I have DAX calculation to get data till ASof date and Below is the DAX to get ASOF date.

 

P Listing =

VAR _Date = CALCULATE(MAX(Datecalendar[TheDate]))

RETURN

CALCULATE( COUNT(C_TIME[Name]),

     C_Time[LstStartDate__c] <= _Date && C_Time[LstStartDate__c] <> Blank() &&

     (C_Time[LstEnd_Date__c] = Blank() || C_Time[LstEnd_Date__c] > _Date) &&

     C_TIME[MIR_End_Date__c] <> BLANK() && C_TIME[MIR_End_Date__c] <= _Date &&

     C_TIME[MType__c] <> "Disposition" ,

    C_TIME[MR_Start_Date__c] <> BLANK() &&

    (C_Time[Yar_Date__c] = BLANK() || C_Time[Yar_Date__c] > _Date))

 

Requirment :  Based on slicer selection

Example if user selects Calendar dates between 22/04/2023 to 25/04/2023, I need to get below data.

MarketAS of 04/22AS of 04/23AS of 04/24AS of 04/25TotalNumber of days
Atl11878344
Chr11111010424

Final Output

 

MarketTotal / Number of days
Atl8.5
Chr10.5

 

Something like this?

lbendlin_0-1682556046155.png

 

 

You can use averagex() instead of sumx() for the final result.

 

see attached.

Helpful resources

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

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

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