Forum Discussion

TriveniN's avatar
TriveniN
Helper II
3 years ago

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

  • Anonymous's avatar
    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