Forum Discussion

Help_me's avatar
Help_me
Frequent Visitor
5 months ago
Solved

How to write this IF statement for same date, but different statuses?

Hello,

I have the two columns below in the same table. "Cookie Type" is text field and "Baked_Date" is a date value.
How can I write the IF statement in DAX for the concept: If the same baked_date for Cookie_type "Chewy" and "Chunky", then "Eat", otherwise "do not eat". I added the "Grape" value to show that there are other values in the dataset that are not relevant. 

Cookie TypeBaked_Date
Chewy03/27
Grape03/27
Chunky03/27

 

Thank you!

  • Help_me 

     

    Calculated column:

    Eat Flag = 
    VAR CurrentDate = 'Table'[Baked_Date]
    RETURN
    IF(
    CALCULATE(
    COUNTROWS('Table'),
    'Table'[Baked_Date] = CurrentDate,
    'Table'[Cookie Type] IN {"Chewy", "Chunky"}
    ) = 2,
    "Eat",
    "Do not eat"
    )

    Checks if both Chewy + Chunky exist on same Baked_Date.

6 Replies

  • Help_me 

     

    Calculated column:

    Eat Flag = 
    VAR CurrentDate = 'Table'[Baked_Date]
    RETURN
    IF(
    CALCULATE(
    COUNTROWS('Table'),
    'Table'[Baked_Date] = CurrentDate,
    'Table'[Cookie Type] IN {"Chewy", "Chunky"}
    ) = 2,
    "Eat",
    "Do not eat"
    )

    Checks if both Chewy + Chunky exist on same Baked_Date.

  • How can I write the IF statement in DAX

    write to where?  A calculated column? A measure?

     

    Please provide sample data that covers your issue or question completely, in a usable format (not as a screenshot).
    Do not include sensitive information. Do not include anything that is unrelated to the issue or question.
    Please show the expected outcome based on the sample data you provided.

    Need help uploading data? https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-Forum/ba-p/963216
    Want faster answers? https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447523

  • v-achippa's avatar
    v-achippa
    Community Support

    Hi Help_me,

     

    Thank you for reaching out to Microsoft Fabric Community.

     

    Thank you lbendlinFBergamaschi and Kedar_Pande for the prompt response.

     

    As we haven’t heard back from you, we wanted to kindly follow up to check if the solution provided by the user's for the issue worked? or let us know if you need any further assistance.

     

    Thanks and regards,

    Anjan Kumar Chippa

    • v-achippa's avatar
      v-achippa
      Community Support

      Hi @Help_me,

       

      We wanted to kindly follow up to check if the solution provided by the user's for the issue worked? or let us know if you need any further assistance.

       

      Thanks and regards,

      Anjan Kumar Chippa

  • Help_me I am assuming it is for a calculated column. Please try out the below dax to create the Eat Flag Column

     

    Eat Flag Column = VAR CurrentDate = 'Table'[Baked_Date]
    
    VAR HasChewy =
        CALCULATE (
            COUNTROWS ( 'Table' ),
            'Table'[Baked_Date] = CurrentDate,
            'Table'[Cookie Type] = "Chewy"
        )
    
    VAR HasChunky =
        CALCULATE (
            COUNTROWS ( 'Table' ),
            'Table'[Baked_Date] = CurrentDate,
            'Table'[Cookie Type] = "Chunky"
        )
    
    RETURN
    IF ( HasChewy > 0 && HasChunky > 0, "Eat", "Do not eat" )