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

Get Fabric certified for FREE! Don't miss your chance! Learn more

Reply
TriveniN
Helper II
Helper II

How to sum up data based on condition

Hi 

 

Need help on below query

 

Created below measure to get data.

 

Below is the sample data

propcodeName[Lease-SFV]chargepostmonthchargetotalamtSecondYearRentOccupied ratio
atl00021atl00021-AAA10/1/202123510001
Atl00021atl00021-BBB9/1/20211010001
atl00045atl00045-CCC10/1/202125020001
atl00076atl00076-DDD10/1/202119530001
atl00127atl00127-EEE10/1/202123020001
atl00127atl00127-XXX9/1/202125520001

 

If we choose slicer date as October , I need to sum up chargetotalamt for october month data to   SUM(LEASE_SFV[SecondYearRent])   * [OccupiedRatio_Current]  ) for that perticular property.

CALCULATE(
    --Month
    IF(
        ( DATEDIFF(
        MAXX( LEASE_SFV,LEASE_SFV[Lease_Start_Date__c] ) , _dateM, MONTH ) > 12
        && VALUES(ReportPeriod[Type]) = "Month" ),
        ( SUM(LEASE_SFV[SecondYearRent])   * [OccupiedRatio_Current]  )
        +
                 IF(
                  ( DATEDIFF(
        MAXX( LEASE_SFV,LEASE_SFV[Lease_Start_Date__c] ) , _dateM, MONTH ) > 12
        && VALUES(ReportPeriod[Type]) = "Month" ) &&
        FORMAT(MAX(PREMINUMS_YV[chargepostmonth]),"YYYYMM") = FORMAT(_dateM,"YYYYMM")

        ,
        SUM(PREMINUMS_YV[chargetotalamt]),0)
        ,
IF(
        ( DATEDIFF(
        MAXX( LEASE_SFV,LEASE_SFV[Lease_Start_Date__c] ) , _dateM, MONTH ) <= 12
        && VALUES(ReportPeriod[Type]) = "Month" ),
        ( SUM(LEASE_SFV[Rent_on_Lease_Agreement__c])  * [OccupiedRatio_Current]  )
        + IF(
              ( DATEDIFF(
        MAXX( LEASE_SFV,LEASE_SFV[Lease_Start_Date__c] ) , _dateM, MONTH ) <= 12
        && VALUES(ReportPeriod[Type]) = "Month" )
        && FORMAT(MAX(PREMINUMS_YV[chargepostmonth]),"YYYYMM") = FORMAT(_dateM,"YYYYMM") , SUM(PREMINUMS_YV[chargetotalamt]),0)

 

But I am getting below result.

propcodeName[Lease-SFV]chargepostmonthchargetotalamtSecondYearRentOccupied ratioExpected Result(chargetotalamt + (SecondYearRent * Occupied ratio)
atl00021atl00021-AAA10/1/2021235100011235
atl00045atl00045-CCC10/1/2021250200012250
atl00076atl00076-DDD10/1/2021195300013195
atl00127atl00127-EEE10/1/2021230200012230
       
1 REPLY 1
Anonymous
Not applicable

Hi @TriveniN ,

As checked your formula, it seems involve multiple tables. Is there any relationship created among them? Could you please provide some source data in these tables 'LEASE_SFV', 'PREMINUMS_YV' and 'ReportPeriod' (exclude sensitive data) with Text format and your expected result with backend logic and special examples? By the way, is _dateM a variable? It would be helpful to find out the solution. You can refer the following links to share the required info:

How to provide sample data in the Power BI Forum

 

And It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

How to upload PBI in Community

Best Regards

Helpful resources

Announcements
Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 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.