Forum Discussion

ilauzirika's avatar
ilauzirika
Regular Visitor
5 years ago
Solved

Dataverse, Count Rows of lookup table column based on condition within lookup column

Hi! It feels like I am trying to do something very wrong as I cannot seem to find a good answer online. Is there a solution to the custom column that I am trying to build?   I am getting my data fr...
  • edhans's avatar
    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 

     

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