Forum Discussion

o-johnralphp's avatar
o-johnralphp
Icon for Advocate I rankAdvocate I
1 year ago
Solved

Return Missing or Extra Values of a Text String from a Non-Related Table

Hi All,

 

Hope you can help me in meeting several conditons for 2 calculated columns.

I have 2 tables Table1 and Table2 which are unrelated.

I need 2 calculated columns to return the missing or extra contents that were dispensed on Table1 from the Mandatory contents per bundle listed on Table2. 

 

Also DAX should also be able to handle OR (Bundle5) & AND conditions (Bundle6).

Any approach or if possible to incorporate all conditions into 1 calculated column is greatly appreciated.

 

Table 1
Invoice NoPackage TypeDispensed ContentsDesired Output: MissingDesired Output: Extra
123451Bundle1Rice Pasta Milk Butter SugarNonePasta
123452Bundle2Flour Sugar NoneNone
123453Bundle1Flour ButterRice Milk SugarFlour
123454Bundle5Pasta FlourNoneNone
123455Bundle6Sugar Pasta FlourSugarNone

 

Table 2
Package TypeMandatory_Contents
Bundle1Rice Milk Sugar Butter
Bundle2Sugar Flour
Bundle3Spices Sugar Butter
Bundle4Fish Shrimp Meat
Bundle5Rice or Pasta Flour
Bundle6Sugar Sugar Pasta Flour

 

Many Thanks!!!

 

  • Anonymous's avatar
    Anonymous
    1 year ago

    Hi o-johnralphp  ,
    Thanks for reaching out to the Microsoft fabric community forum.


    I tried implementing your requirement using LOOKUPVALUE, but it doesn’t work with your data because LOOKUPVALUE can only handle exact text matches, not concatenated text strings like the ones in your column. It would only work if you split the text into separate rows or values, which would likely disrupt your data structure.

    Instead you can consider using PySpark in Fabric Notebook’s for this type of transformation, as it provides much greater flexibility when working with string operations. Instead of relying on complex DAX calculated columns, you can easily join Table1 and Table2 on Package Type using join(), bringing in the mandatory contents for each package. Once the tables are joined, you can use PySpark’s string and array functions such as split(), array_except(), and array_intersect() to compare the dispensed and mandatory items efficiently. This allows you to identify which items are missing or extra for each record.


    I hope this information helps. Please do let us know if you have any further queries.
    Thank you

7 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi o-johnralphp  ,
    Thanks for reaching out to the Microsoft fabric community forum.


    I tried implementing your requirement using LOOKUPVALUE, but it doesn’t work with your data because LOOKUPVALUE can only handle exact text matches, not concatenated text strings like the ones in your column. It would only work if you split the text into separate rows or values, which would likely disrupt your data structure.

    Instead you can consider using PySpark in Fabric Notebook’s for this type of transformation, as it provides much greater flexibility when working with string operations. Instead of relying on complex DAX calculated columns, you can easily join Table1 and Table2 on Package Type using join(), bringing in the mandatory contents for each package. Once the tables are joined, you can use PySpark’s string and array functions such as split(), array_except(), and array_intersect() to compare the dispensed and mandatory items efficiently. This allows you to identify which items are missing or extra for each record.


    I hope this information helps. Please do let us know if you have any further queries.
    Thank you

  • Hi grazitti_sapna 

    Im getting an error "Failed to resolve name "STRING_SPLIT. It is not a valid table,variable, or function name.

     

    Thanks

    • Natalie_iTalent's avatar
      Natalie_iTalent
      Icon for Administrator rankAdministrator

      Hello o-johnralphp,

      The comment you responded to has been removed from this post for being inaccurate.

       

      Best,

      Natalie H.

      Community Manager 

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi o-johnralphp 

    I wanted to check if you had the opportunity to review the information provided. Please feel free to contact us if you have any further questions.


    Thank you.

    • o-johnralphp's avatar
      o-johnralphp
      Icon for Advocate I rankAdvocate I

      Hi Anonymous ,

       

      Thank you for your time in trying to come up with solution to my requirement and for pointing why this not possible with DAX. Im still new with Power BI so PySpark will be quite a challenge and Im not sure if it will be applicable in my work settings. Thanks again

      • Anonymous's avatar
        Anonymous
        Not applicable

        Hi o-johnralphp ,

        We really appreciate your efforts and for letting us know the update on the issue.

        Please continue using fabric community forum for your further assistance.


        Thank you