Forum Discussion

Fxelixe's avatar
Fxelixe
Frequent Visitor
3 years ago
Solved

Re:

Hi

 

So i have trouble to create logic to solve package issue.

the goal is to put remark when customer buy our package which consist of several products

 

if customer didn't buy the specific product then we remark it as 0, if buy all of the specific products then we remark it as 1

Here's my DAX logic 

Package Remark = CALCULATE([Unit Sold],[Unit Sold]>=1.0,filter('Product',[Product Name] IN {"Product A","Product B","Product C","Product D"}))

Here's some excel visualization for the expected output


Well in excel i could easily do COUNT IF cell value >= 1.5 is equal to 6 then 1 , if false 0. then sum it. 
but i cannot do that easily in power BI. still learning to be better.

Thank you

  • Hi,

    I am not sure how your datamodel looks like, but please check the below picture and the attached pbix file.

    It is for creating a measure.

    I hope the below can provide some ideas on how to create a solution for your datamodel.

     

     

     

    Expected output: =
    VAR _productAcondition =
        CALCULATE ( SUM ( Data[Quantity] ), Package[Product Name] = "Product A" ) <> 0
    VAR _productBcondition =
        CALCULATE ( SUM ( Data[Quantity] ), Package[Product Name] = "Product B" ) <> 0
    VAR _productCcondition =
        CALCULATE ( SUM ( Data[Quantity] ), Package[Product Name] = "Product C" ) <> 0
    VAR _productDcondition =
        CALCULATE ( SUM ( Data[Quantity] ), Package[Product Name] = "Product D" ) <> 0
    RETURN
        IF (
            HASONEVALUE ( User[User] ),
            _productAcondition * _productBcondition * _productCcondition * _productDcondition
        )
    

     

     

  • Update:

    Already have the answer but kinda complicated.

    the idea is to create multiple var to count the products
    and then return it using floor
    return
    floor(item(1)+item(2)+....+Item(n),n)/n


  • Hi,

    Thank you for your message, and please check the below picture and the attached pbix file.

    I tried to create a sample pbix file like below.

     

     

     

     

     

     

10 Replies

  • hi Fxelixe 

    IN is OR logic, but it seems you expect a AND logic. Try to modify it firstly.

     

    If the issue persists, it would be necessary to also provide more info about your data model: tables, columns and relationships. It seems you have at least a Product Table and Fact Table, maybe a Customer Table as well. 

    • Fxelixe's avatar
      Fxelixe
      Frequent Visitor

      yes I already think to use AND, but AND logic only works for 2 item. I need flexibilities to determine # of products

      • FreemanZ's avatar
        FreemanZ
        Super User

        you can use && to combine Boolean expressions as many as possible.

  • Hi,

    I am not sure how your datamodel looks like, but please check the below picture and the attached pbix file.

    It is for creating a measure.

    I hope the below can provide some ideas on how to create a solution for your datamodel.

     

     

     

    Expected output: =
    VAR _productAcondition =
        CALCULATE ( SUM ( Data[Quantity] ), Package[Product Name] = "Product A" ) <> 0
    VAR _productBcondition =
        CALCULATE ( SUM ( Data[Quantity] ), Package[Product Name] = "Product B" ) <> 0
    VAR _productCcondition =
        CALCULATE ( SUM ( Data[Quantity] ), Package[Product Name] = "Product C" ) <> 0
    VAR _productDcondition =
        CALCULATE ( SUM ( Data[Quantity] ), Package[Product Name] = "Product D" ) <> 0
    RETURN
        IF (
            HASONEVALUE ( User[User] ),
            _productAcondition * _productBcondition * _productCcondition * _productDcondition
        )
    

     

     

    • Fxelixe's avatar
      Fxelixe
      Frequent Visitor

      yes i also think the same idea hahaha. thank you, i hope in the future someone will be helped by this thread

    • Fxelixe's avatar
      Fxelixe
      Frequent Visitor

      Hi Jihwan_Kim ,

      your dax works and helps me a lot!, but suddenly the problem got more complex for me:

      1.  package is valid if each product's sold is >= 1.5
      2.  the result can be cumulative on the last solution it would be total = 2   
      (my hypothesis because if we use IF statement, the calculation will treat them as logical, not cumulative)
      3.  each user has one group and the result expected to be summarize by group

      Here's the updated table


      and then if grouped by "Group"

      thank you so much

      • Jihwan_Kim's avatar
        Jihwan_Kim
        Super User

        Hi,

        Thank you for your message, and please check the below picture and the attached pbix file.

        I tried to create a sample pbix file like below.

         

         

         

         

         

         

  • Fxelixe's avatar
    Fxelixe
    Frequent Visitor

    Update:

    Already have the answer but kinda complicated.

    the idea is to create multiple var to count the products
    and then return it using floor
    return
    floor(item(1)+item(2)+....+Item(n),n)/n


  • tamerj1's avatar
    tamerj1
    Community Champion

    Hi Fxelixe 

    please try

    Package Remark =
    VAR Count1 =
    COUNTROWS (
    FILTER (
    VALUES ( 'Product'[Product Name] ),
    'Product'[Product Name]
    IN { "Product A", "Product B", "Product C", "Product D" }
    )
    )
    RETURN
    IF ( ISINSCOPE ( 'Product'[Product Name] ), Count1, IF ( Count1 = 4, 1 ) )