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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
Data-Papa
Frequent Visitor

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.

 

2 ACCEPTED SOLUTIONS

hi @Data-Papa ,

 

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:

FreemanZ_0-1700030740143.png

View solution in original post

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

View solution in original post

7 REPLIES 7
Data-Papa
Frequent Visitor

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

hi @Data-Papa ,

 

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:

FreemanZ_0-1700030740143.png

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.

hi @Data-Papa ,

 

try like:

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

 

it worked like:

FreemanZ_0-1700052728394.png

 

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

fantastic, that's got it thanks @FreemanZ !

Interestingly though, it does seem to throw up an 'exceeds resources' error on occasion; might there have been an alternative, more optimal way to achieve the same result?


I was toying with SUMMARIZE, creating columns with IF statements as to whether the row had specific InstIDs and then creating a measure off the back of that, an iterator to return the count of rows where the flag criteria of the respective column was met. 

 

Not sure if it would have been better for performance to do something like this?

ThxAlot
Super User
Super User

ThxAlot_0-1699905306698.png



Expertise = List.Accumulate(


        {Days as from Today},


        {Skills and Knowledge},


        (Current, Everyday) => Current & Day.LeanAndPractise(Everyday)


)



Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

AugPowerBI_Carousel

Power BI Monthly Update - August 2024

Check out the August 2024 Power BI update to learn about new features.

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.