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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.

Reply
InsightSeeker
Helper III
Helper III

Help Needed with DAX Formula Logic

Hello

 

I have created a DAX formula as shown below, but I am having a slight issue with the logic.

 

I need the result to be either valid or error only for the customer (_Customer) specified in the DAX. For all other customers, it should return true. Is there a way to do this?

 

Validation =

var _left = LEFT('TABLE_1'[Card_Number],4)

var _right = RIGHT('TABLE_1'[Card_Number],4)

var _len = LEN('TABLE_1'[Card_Number])

var _customer = 'TABLE_1'[fop_customer_code]

var _auth = 'TABLE_1'[Card_Auth_Code]

var _mode = 'TABLE_1'[settle_name]

var _tktdate = 'TABLE_1'[Ticket_Date]

RETURN if(

_mode = "Card" || _mode = "OCCF"  && _customer = "0000103900"  && _len =15  && _left = "3744"  && _right = "9380" && _auth <> BLANK() ||

_tktdate > DATE(24,02,01) && _mode = "Card" || _mode = "OCCF" && _customer = "0000103902"  && _len =15  && _left = "3744"  && _right = "9380" && _auth <> BLANK() ||

_tktdate < DATE(24,01,31) && _mode = "Card" || _mode = "OCCF" && _customer = "0000103902"  && _len =15  && _left = "3744"  && _right = "1031" && _auth <> BLANK() ||

_mode = "Card" || _mode = "OCCF" && _customer = "0000107500"  && _len =15  && _left = "3744"  && _right = "3912" && _auth <> BLANK() ||

_mode = "Card" || _mode = "OCCF" && _customer = "0000107501"  && _len =15  && _left = "3744"  && _right = "3912" && _auth <> BLANK() ||

,"Valid","Error")

1 ACCEPTED SOLUTION
rajendraongole1
Super User
Super User

Hi @InsightSeeker - I have modified a slight change in condition as per customer code is in specified list , can you try below 

 

Validation =
var _left = LEFT('TABLE_1'[Card_Number], 4)
var _right = RIGHT('TABLE_1'[Card_Number], 4)
var _len = LEN('TABLE_1'[Card_Number])
var _customer = 'TABLE_1'[fop_customer_code]
var _auth = 'TABLE_1'[Card_Auth_Code]
var _mode = 'TABLE_1'[settle_name]
var _tktdate = 'TABLE_1'[Ticket_Date]

RETURN
IF(
_customer IN {"0000103900", "0000103902", "0000107500", "0000107501"},
IF(
(_mode = "Card" || _mode = "OCCF") && _customer = "0000103900" && _len = 15 && _left = "3744" && _right = "9380" && _auth <> BLANK() ||
_tktdate > DATE(2024, 02, 01) && (_mode = "Card" || _mode = "OCCF") && _customer = "0000103902" && _len = 15 && _left = "3744" && _right = "9380" && _auth <> BLANK() ||
_tktdate < DATE(2024, 01, 31) && (_mode = "Card" || _mode = "OCCF") && _customer = "0000103902" && _len = 15 && _left = "3744" && _right = "1031" && _auth <> BLANK() ||
(_mode = "Card" || _mode = "OCCF") && _customer = "0000107500" && _len = 15 && _left = "3744" && _right = "3912" && _auth <> BLANK() ||
(_mode = "Card" || _mode = "OCCF") && _customer = "0000107501" && _len = 15 && _left = "3744" && _right = "3912" && _auth <> BLANK(),
"Valid",
"Error"
),
"True"

 

the above logic returns , if the customer code matches any specified values, it returns valid or error

if the customer code doesnot matches to go to the true loop and returns.

 

Try the above one statement.

 

Did I answer your question? Mark my post as a solution! This will help others on the forum!
Appreciate your Kudos!!





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Your solutions is great @rajendraongole1 , I tested your DAX expression with test data and it worked fine. I've optimized the DAX expression you provided.

Hi, @InsightSeeker 

Here's the test data I used:

vjianpengmsft_0-1717557396182.png

Here are the optimized DAX expressions:

Validation1 = 
var _left = LEFT('TABLE_1'[Card_Number],4)
var _right = RIGHT('TABLE_1'[Card_Number],4)
var _len = LEN('TABLE_1'[Card_Number])
var _customer = 'TABLE_1'[fop_customer_code]
var _auth = 'TABLE_1'[Card_Auth_Code]
var _mode = 'TABLE_1'[settle_name]
var _tktdate = 'TABLE_1'[Ticket_Date]
RETURN 
if(
NOT _customer  IN {"0000103900","0000103902","0000107500","0000107501"}
,"TRUE",
if(

_mode IN {"Card" , "OCCF"}  &&
_len = 15 &&
_left = "3744"  &&
_auth <> BLANK() && (
    _customer = "0000103900" && _right = "9380" ||
    _tktdate > DATE(24,02,01) && _customer = "0000103902"&&_right="9380"||
    _tktdate < DATE(24,02,01) && _customer = "0000103902"&&_right="1031" ||
    _customer = "0000107500" && _right = "3912" ||
    _customer = "0000107501" && _right = "3912" 
)
,"Valid","Error")
)

TURE is returned when the customer is not in the account that you define. Here are the results:

vjianpengmsft_2-1717557746612.png

I've provided the PBIX file used this time below.

 

 

 

How to Get Your Question Answered Quickly

If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .

Best Regards

Jianpeng Li

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

rajendraongole1
Super User
Super User

Hi @InsightSeeker - I have modified a slight change in condition as per customer code is in specified list , can you try below 

 

Validation =
var _left = LEFT('TABLE_1'[Card_Number], 4)
var _right = RIGHT('TABLE_1'[Card_Number], 4)
var _len = LEN('TABLE_1'[Card_Number])
var _customer = 'TABLE_1'[fop_customer_code]
var _auth = 'TABLE_1'[Card_Auth_Code]
var _mode = 'TABLE_1'[settle_name]
var _tktdate = 'TABLE_1'[Ticket_Date]

RETURN
IF(
_customer IN {"0000103900", "0000103902", "0000107500", "0000107501"},
IF(
(_mode = "Card" || _mode = "OCCF") && _customer = "0000103900" && _len = 15 && _left = "3744" && _right = "9380" && _auth <> BLANK() ||
_tktdate > DATE(2024, 02, 01) && (_mode = "Card" || _mode = "OCCF") && _customer = "0000103902" && _len = 15 && _left = "3744" && _right = "9380" && _auth <> BLANK() ||
_tktdate < DATE(2024, 01, 31) && (_mode = "Card" || _mode = "OCCF") && _customer = "0000103902" && _len = 15 && _left = "3744" && _right = "1031" && _auth <> BLANK() ||
(_mode = "Card" || _mode = "OCCF") && _customer = "0000107500" && _len = 15 && _left = "3744" && _right = "3912" && _auth <> BLANK() ||
(_mode = "Card" || _mode = "OCCF") && _customer = "0000107501" && _len = 15 && _left = "3744" && _right = "3912" && _auth <> BLANK(),
"Valid",
"Error"
),
"True"

 

the above logic returns , if the customer code matches any specified values, it returns valid or error

if the customer code doesnot matches to go to the true loop and returns.

 

Try the above one statement.

 

Did I answer your question? Mark my post as a solution! This will help others on the forum!
Appreciate your Kudos!!





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.

Top Kudoed Authors