Forum Discussion
Dataverse, Count Rows of lookup table column based on condition within lookup column
- 5 years ago
Your code should look like this. You are missing the each keyword in Table.SelectRows, and since Table.SelectRows is already referencing the [Orders] table you do not need to refer to it again, just to the product type within a field. You were definitely on the right path though, just need to tweak your syntax a bit.
Table.RowCount( Table.SelectRows( [Orders], each [Product Type] = "Potato" ) )
That may not perform well depending on the data source. It might be faster to:- expand all of those orders in another table or access the orders table directly
- Do your filter for the Potato product type
- Do a Group By then count the records
- Merge that result with your original table.
The above will fold on a SQL table and the server does all of the work. I think the DataVerse will to. The code in the box above most assuredly will not ilauzirika
- 5 years ago
Hello ilauzirika
when I read that I really asked me if you then would need to do this for other product types and maybe other manipulations as well. If yes then I would say it would be the wrong approach. You have here basically two datatables combined as one. I would suggest in this case to load your customer-table into your datamodel and create a new table from customer id and all expanded order-table, connect them in Power BI and create measures.
Hope I was clear enough
If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too
Have fun
Jimmy
Thank you to both of you, I definitely took the wrong approach at this. I tried the corrected formula as indicated by edhans, just to learn what the load would be on the system. well, needless to say, the PC crashed after using over 20GB of Virtual memory hahaha.... lesson learnt.
If I could accept both posts as a solution I would. I am using edhans solution as it works very well for my setup. But both solutions make a lot of sense and are working correctly (I tested both).
- edhans5 years agoCommunity Champion
Glad to help ilauzirika - and you can accept both solutions. I went ahead and accepted Jimmy801 's solution for you. Either way, glad you got the answer you needed.