Forum Discussion

ElvirBotic's avatar
ElvirBotic
Icon for Helper III rankHelper III
4 years ago

Count Inspections for each Location Once and only Once

I have a dataset where I need to count completed Inspections for each location and count it only once. I will create a table of mock data I am working with. The users will inspect different locations. Each quarter a location needs to complete 1 Long inspection and 2 short inspections. There are Instances where users will complete a long inspection twice in a quarter and we do not want it to count more than once. Same goes for short inspections. If the user completes more than 2 short inspections we only want to count two for each location. I hope that clarifys things. If I can answer anymore questions I would be glad to. 

Data:

SiteIDDate CompletedInspection Type
101/15/2022Long
101/16/2022Long
202/11/2022Short
304/04/2022Short
103/11/2022Short
202/06/2022Short
102/15/2022Long
203/04/2022Short

 

Result:

SiteTypeTotalQuarter
1Long11
1Short01
2Long01
2Short21
3Long01
3Short12

4 Replies

  • Try

    Total inspections =
    var numInspections = CALCULATE( COUNTROWS('Data') )
    var inspectionType = SELECTEDVALUE('Data'[Inspection type])
    var result = IF( inspectionType = "Long", IF( numInspections > 1, 1, numInspections),
    IF( numInspections > 2, 2, numInspections) )
    return result
    • ElvirBotic's avatar
      ElvirBotic
      Icon for Helper III rankHelper III

      I tried your approach and when I add the measure to a matrix visual my totals row is 1, which is not correct. 

      • johnt75's avatar
        johnt75
        Icon for Super User rankSuper User

        Rename the original measure to Individual Inspections and then create a new measure as

        Total Inspections = IF( ISINSCOPE( 'Data'[Site]), [Individual Inspections],
        SUMX( ADDCOLUMNS( SUMMARIZE( 'Data', 'Data'[Site], 'Data'[Type]), 
        "@value", CALCULATE( [Individual Inspections] ), [@value] )
        )