Forum Discussion
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 Type | Baked_Date |
| Chewy | 03/27 |
| Grape | 03/27 |
| Chunky | 03/27 |
Thank you!
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
- Kedar_PandeSuper User
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.
- lbendlinSuper User
How can I write the IF statement in DAXwrite 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 - FBergamaschiSuper User
Hi Help_me
please provide more sample rows and clarify what lbendlin asked: do you need to create a column in the table or a measure for a visual?
If this helped, please consider giving kudos and mark as a solution
@me in replies or I'll lose your thread
Want to check your DAX skills? Answer my biweekly DAX challenges on the kubisco Linkedin page
Consider voting this Power BI idea
Francesco Bergamaschi
MBA, M.Eng, M.Econ, Professor of BI
- v-achippaCommunity Support
Hi Help_me,
Thank you for reaching out to Microsoft Fabric Community.
Thank you lbendlin, FBergamaschi 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
- Jai-RathinavelSuper User
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" )