Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Complex If Then Statement

Not sure how to create this IF Then statement, any help would be appreciated. I have two variables that need to be analyzed and a new column created.

 

Would like to know if it can be done using DAX functions or the if then builder in the Query mode.

 

Prosecution Date, Court Date.

 

If both variables are blank = Unknown

If Prosecution is blank and court has a value = "Court"

If Court is blank and Prosecution has a value= "Prosec"

If both variables have a value = "Court" or "Prosec" whichever has the newest date.

 

 

1 ACCEPTED SOLUTION
az38
Community Champion
Community Champion

Hi @Anonymous 

there are 2 options:

1. DAX using SWITCH()

Column = SWITCH(TRUE(),
ISBLANK([Prosecution Date]) && ISBLANK([Court Date]), "Unknown",
ISBLANK([Prosecution Date]) && NOT(ISBLANK([Court Date])), "Court",
NOT(ISBLANK([Prosecution Date])) && ISBLANK([Court Date]), "Prosec",
[Prosecution Date]>[Court Date], "Prosec",
"Court"
)

2. Power QUery Custom Column

= if [Prosecution Date] = null and [Court Date] = null then "Unknown"
else if [Prosecution Date] = null and [Court Date] <> null then "Court"
else if [Prosecution Date] <> null and [Court Date] = null then "Prosec"
else if [Prosecution Date] > [Court Date] then "Prosec"
else "Court"

 


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

View solution in original post

6 REPLIES 6
amitchandak
Super User
Super User

Try a new column like

Switch( true(),
isblank([Prosecution Date]) && isblank([Court Date]) ,"Unknown",
isblank([Prosecution Date]) && not(isblank([Court Date])),"Court",
not(isblank([Prosecution Date])) && (isblank([Court Date])),"Prosec",
max([Prosecution Date],[Court Date])
)

 

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
az38
Community Champion
Community Champion

Hi @Anonymous 

there are 2 options:

1. DAX using SWITCH()

Column = SWITCH(TRUE(),
ISBLANK([Prosecution Date]) && ISBLANK([Court Date]), "Unknown",
ISBLANK([Prosecution Date]) && NOT(ISBLANK([Court Date])), "Court",
NOT(ISBLANK([Prosecution Date])) && ISBLANK([Court Date]), "Prosec",
[Prosecution Date]>[Court Date], "Prosec",
"Court"
)

2. Power QUery Custom Column

= if [Prosecution Date] = null and [Court Date] = null then "Unknown"
else if [Prosecution Date] = null and [Court Date] <> null then "Court"
else if [Prosecution Date] <> null and [Court Date] = null then "Prosec"
else if [Prosecution Date] > [Court Date] then "Prosec"
else "Court"

 


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn
Anonymous
Not applicable

I am fairly new to Power Bi does "[]" indicate a table? All of my variables are columns in one table.

 

@Anonymous -

 

The documentation shows a nice explanation of syntax. https://docs.microsoft.com/en-us/dax/dax-syntax-reference

image.png

 

 

 






Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

Proud to be a Super User!



az38
Community Champion
Community Champion

@Anonymous 

[] its a column name inside your table.

Table[Column] - full syntax

 


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn
Anonymous
Not applicable

Thank you so much! This has been so helpful.

 

Do you know how I culd use this new column in an if then statement sort of thing but using a DAX function instead? Like if = court then [Court Statement] if = Prosec then [Prosec Statement], else unknown.

 

I would do the if then in power query mode but working from home I lost access to the server adn can't update the data. So no power query for me today.

 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.