Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago
Solved

counting instances where logic occurs on 2 rows

 

employeeInstIDDateTimetransactionIDInstanceNameDate
7O22230/05/2023 09:11YWJPMView product succeeded30-May-23
8O22211/09/2023 10:32YWJKNView product succeeded11-Sep-23
4O11114/06/2023 20:24YWJH84View product failed14-Jun-23
2O22221/07/2023 07:39YWJA24View product succeeded21-Jul-23
3O22205/04/2023 09:19YWJ7V5View product succeeded05-Apr-23
3O33305/04/2023 09:20YWJ7V5Update product failed05-Apr-23

 

I'm trying to create a measure where I count all the occurences of 'transcationID' "YWJ7V5" occurs; the employee has done step 1 ('InstID' "O222") and viewed the product, and step 2 ('InstID' "O333") failed to update the product. 

 

I want to count on 'transcationID', so that the count would be 1.

 

For context, I am trying to create multiple measures so that I can track where the failure has occured on a journey when making changes to a product in the database. Not sure if I should be created a calculated column?

 

Many thanks in advance.

 

  • FreemanZ's avatar
    FreemanZ
    2 years ago

    hi Anonymous ,

     

    Not sure if i fully get you, try to plot a card visual with a measure like:

    measure = 
    VAR _list =
    FILTER(
        VALUES(data[transactionID]),
        VAR _list = CALCULATETABLE(VALUES(data[InstID]))
        VAR _diff = EXCEPT({"O222", "O333"}, _list) 
        RETURN ISEMPTY(_diff)
    )
    VAR _result1 = COUNTROWS(_list)
    VAR _result2 = CONCATENATEX(_list, data[transactionID], ", ") //for test only
    RETURN  _result1

     

    it worked like:

  • or this shall also work:

    measure4 = 
    VAR _list =
    FILTER(
        VALUES(data[transactionID]),
        VAR _list2 = CALCULATETABLE(VALUES(data[InstID]))
        VAR _diff =  EXCEPT({"O222", "O333"}, _list2)
        RETURN COUNTROWS(_list2)=2 && ISEMPTY(_diff) 
    )
    VAR _result1 = COUNTROWS(_list)
    VAR _result2 = CONCATENATEX(_list, data[transactionID], ", ")
    RETURN  _result1

7 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    thanks ThxAlot, but this isn't quite what I'm looking for; your DAX is looking for a specific transactionid. The table was an example, but there are thousands of transactions that I'm trying to account for when this happens.  I also don't need to concatenate the count of employees.

     

    I just need to count the amount of times a transaction has occurred, where an employee has viewed the product succesfully, but failed to update the product. 

     

    I've updated the table below to make the example clearer. Now the count would be 2 because of transactions YWJ7V5 && 94GGG

     

     

    employeeInstIDDateTimetransactionIDInstanceNameDate
    7O22230/05/2023 09:11YWJPMView product succeeded30-May-23
    8O22211/09/2023 10:32YWJKNView product succeeded11-Sep-23
    4O11114/06/2023 20:24YWJH84View product failed14-Jun-23
    2O22221/07/2023 07:39YWJA24View product succeeded21-Jul-23
    3O22205/04/2023 09:19YWJ7V5View product succeeded05-Apr-23
    3O33305/04/2023 09:20YWJ7V5Update product failed05-Apr-23
    12O22205/10/2023 09:45LLAFGHView product succeeded05-Oct-23
    6O22217/09/2023 09:4594GGGView product succeeded17-Sep-23
    6O33317/09/2023 09:4694GGG Update product failed17-Sep-23
    6O22213/01/2023 11:136HYT3View product succeeded13-Jan-23
    5O22215/01/2023 11:33PAS33View product succeeded15-Jan-23
    9O22205/02/2023 11:13JGADGView product succeeded05-Feb-23
    9O44405/02/2023 11:14JGADGUpdate product succeeded05-Feb-23

     

     

    thanks again, appreciate your help

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

      hi Anonymous ,

       

      Not sure if i fully get you, try to plot a card visual with a measure like:

      measure = 
      VAR _list =
      FILTER(
          VALUES(data[transactionID]),
          VAR _list = CALCULATETABLE(VALUES(data[InstID]))
          VAR _diff = EXCEPT({"O222", "O333"}, _list) 
          RETURN ISEMPTY(_diff)
      )
      VAR _result1 = COUNTROWS(_list)
      VAR _result2 = CONCATENATEX(_list, data[transactionID], ", ") //for test only
      RETURN  _result1

       

      it worked like:

      • Anonymous's avatar
        Anonymous
        Not applicable

        hi FreemanZ ,

         

        That almost works, thanks! It's still not quite right though.

         

        I need "_result1" to bring back all the 'data[transactionID]' where "O222, O333" is applicable only. At the moment, it is bringing back 'data[transactionID]' rows where there is "O222, O333" and others. To clarify I will edit the table again:

         

         

         

        employeeInstIDDateTimetransactionIDInstanceNameDate
        7O22230/05/2023 09:11YWJPMView product succeeded30-May-23
        8O22211/09/2023 10:32YWJKNView product succeeded11-Sep-23
        4O11114/06/2023 20:24YWJH84View product failed14-Jun-23
        2O22221/07/2023 07:39YWJA24View product succeeded21-Jul-23
        3O22205/04/2023 09:19YWJ7V5View product succeeded05-Apr-23
        3O33305/04/2023 09:20YWJ7V5Update product failed05-Apr-23
        12O22205/10/2023 09:45LLAFGHView product succeeded05-Oct-23
        6O22217/09/2023 09:4594GGGView product succeeded17-Sep-23
        6O33317/09/2023 09:4694GGG Update product failed17-Sep-23
        6O22213/01/2023 11:136HYT3View product succeeded13-Jan-23
        5O22215/01/2023 11:33PAS33View product succeeded15-Jan-23
        9O22205/02/2023 11:13JGADGView product succeeded05-Feb-23
        44O22217/03/2023 11:45HGHA3View product succeeded30-Mar-23
        44O33317/03/2023 11:46HGHA3 Update product failed30-Mar-23
        44O77717/03/2023 11:46HGHA3Delete product failed30-Mar-23

         

         

        In the above example, we can see data[transactionid] "HGHA3" has "O222" and "O333", but also "O777". I therefore do not want to count this and the '_result1' should still return 2.

         

        I just need to count the number of rows of data[transactionid] where data[InstID] is "O222" && "O333", but Power BI won't let me for some reason!


        Thanks again.