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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
refint_650
Helper I
Helper I

if else conditions in dax format

Hi All

 

how to rewrite in dax format.

 

if (A.Orderdate < @CalendarDate AND (A.purchasedate > @CalendarDate OR A.purchaseDate IS NULL))
OR (A.Orderdate > @CalendarDate) then count(id) else 0

 

vs

1 ACCEPTED SOLUTION

@TheoC 

 

how can add i more filter condition  calendardate  = startofmonth(_OrderDate)

 

 

Calc Column = 

VAR _OrderDate = YourTableName[Orderdate]
VAR _PurchaseDate = YourTableName[PurchaseDate]
VAR _CalendarDate = YourTableName[CalendarDate]

VAR _1 = _OrderDate < _CalendarDate
VAR _2 = _PurchaseDate > _CalendarDate || _PurchaseDate = 0
VAR _3 = _OrderDate > _CalendarDate

RETURN

IF ( _1 && _2 && _3 = TRUE , COUNT ( YourTableName[ID] ) , 0 )

 

View solution in original post

10 REPLIES 10
TheoC
Super User
Super User

Hi @refint_650 

 

Can you try something like the following calculated column:

 

Calc Column = 

VAR _OrderDate = YourTableName[Orderdate]
VAR _PurchaseDate = YourTableName[PurchaseDate]
VAR _CalendarDate = YourTableName[CalendarDate]

VAR _1 = _OrderDate < _CalendarDate
VAR _2 = _PurchaseDate > _CalendarDate || _PurchaseDate = 0
VAR _3 = _OrderDate > _CalendarDate

RETURN

IF ( _1 && _2 && _3 = TRUE , COUNT ( YourTableName[ID] ) , 0 )

You may need to make slight adjustments to get the syntax right but hopefully it works out.

 

Thanks heaps,

Theo

If I have posted a response that resolves your question, please accept it as a solution to formally close the post.

Also, if you are as passionate about Power BI, DAX and data as I am, please feel free to reach out if you have any questions, queries, or if you simply want to connect and talk to another data geek!

Want to connect?www.linkedin.com/in/theoconias

@TheoC 

 

how can add i more filter condition  calendardate  = startofmonth(_OrderDate)

 

 

Calc Column = 

VAR _OrderDate = YourTableName[Orderdate]
VAR _PurchaseDate = YourTableName[PurchaseDate]
VAR _CalendarDate = YourTableName[CalendarDate]

VAR _1 = _OrderDate < _CalendarDate
VAR _2 = _PurchaseDate > _CalendarDate || _PurchaseDate = 0
VAR _3 = _OrderDate > _CalendarDate

RETURN

IF ( _1 && _2 && _3 = TRUE , COUNT ( YourTableName[ID] ) , 0 )

 

@refint_650 will send it to you when I get in front of computer. on phone atm sorry.

If I have posted a response that resolves your question, please accept it as a solution to formally close the post.

Also, if you are as passionate about Power BI, DAX and data as I am, please feel free to reach out if you have any questions, queries, or if you simply want to connect and talk to another data geek!

Want to connect?www.linkedin.com/in/theoconias

@TheoC 

 

appreciate for response 🙂

@refint_650 did the formula work for you? If so, please mark as solution. 

 

If I have posted a response that resolves your question, please accept it as a solution to formally close the post.

Also, if you are as passionate about Power BI, DAX and data as I am, please feel free to reach out if you have any questions, queries, or if you simply want to connect and talk to another data geek!

Want to connect?www.linkedin.com/in/theoconias

@TheoC 

 

It worked greate. but i forgot add one more condition to same logic

only show data where  calendardate  = startofmonth(_OrderDate)

@refint_650 still on phone so apologies for any syntax errors! Hope this helps!

 

Calc Column = 

 

VAR _OrderDate = YourTableName[Orderdate]

VAR _PurchaseDate = YourTableName[PurchaseDate]

VAR _CalendarDate = YourTableName[CalendarDate]

VAR _StartOfMonth = STARTOFMONTH ( YourTableName[CalendarDate] )

 

VAR _1 = _OrderDate < _CalendarDate

VAR _2 = _PurchaseDate > _CalendarDate || _PurchaseDate = 0

VAR _3 = _OrderDate > _CalendarDate

VAR _4 = _StartOfMonth = _CalendarDate

 

RETURN

 

IF ( _1 && _2 && _3 && _4 = TRUE , COUNT ( YourTableName[ID] ) , 0 )

If I have posted a response that resolves your question, please accept it as a solution to formally close the post.

Also, if you are as passionate about Power BI, DAX and data as I am, please feel free to reach out if you have any questions, queries, or if you simply want to connect and talk to another data geek!

Want to connect?www.linkedin.com/in/theoconias

@TheoC 

 

Much Appreciated. I will slightly tweak expression as year as primary & Month(optional)  as secondary  slicers .

 

ex: I'm doing VAR _1 = _OrderDate < selectedvalue( _CalendarDate)

@TheoC 

 

I will give try and let u know  @TheoC  thank you.

 

vs

All good! Look forward to hearing from you.

 

If I have posted a response that resolves your question, please accept it as a solution to formally close the post.

Also, if you are as passionate about Power BI, DAX and data as I am, please feel free to reach out if you have any questions, queries, or if you simply want to connect and talk to another data geek!

Want to connect?www.linkedin.com/in/theoconias

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.