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

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

Reply
Anonymous
Not applicable

DAX to compare two columns having different data types

Hi guys,

 

When using the DAX sentence below:

 

Week Accuracy (Last 13wks Flag) %:=VAR AggCode = Switch(

True(),

Max(tAccuracy[Aggregatiion Code]) = 2 && MAXA(tDate[Last 13wks Flag]) = "TRUE", [Week Product ID Location Accuracy %],

Max (tAccuracy[Aggregatiion Code]) = 1 && MAXA(tDate[Last 13wks Flag]) = "TRUE", [Week Product Group Location Accuracy %],

Max (tAccuracy[Aggregatiion Code]) = 0 && MAXA(tDate[Last 13wks Flag]) = "TRUE", [Week Product Group Accuracy %]

 

)

Return

IF ( AggCode > 1, 0, if(AND ( AggCode <= 1, AggCode > 0 ), AggCode, 0 ))

I am getting an error saying that is not possible to compare values of type integer and values of type text. I tried to use VALUE on 

MAXA(VALUE(tDate[Last 13wks Flag])) = "TRUE" but still didn't work. Any suggestion?

1 ACCEPTED SOLUTION
AmiraBedh
Super User
Super User

If Last 13wks Flag is stored as text but actually represents a boolean, I think you'll need to properly convert this text to a numeric or boolean type that can be compared correctly. 

 

Week Accuracy (Last 13wks Flag) %:=VAR AggCode = Switch(
    True(),
    Max(tAccuracy[Aggregation Code]) = 2 && SWITCH(MAXA(tDate[Last 13wks Flag]), "TRUE", 1, "FALSE", 0, 0) = 1, [Week Product ID Location Accuracy %],
    Max(tAccuracy[Aggregation Code]) = 1 && SWITCH(MAXA(tDate[Last 13wks Flag]), "TRUE", 1, "FALSE", 0, 0) = 1, [Week Product Group Location Accuracy %],
    Max(tAccuracy[Aggregation Code]) = 0 && SWITCH(MAXA(tDate[Last 13wks Flag]), "TRUE", 1, "FALSE", 0, 0) = 1, [Week Product Group Accuracy %]
)
Return
IF ( AggCode > 1, 0, IF(AND ( AggCode <= 1, AggCode > 0 ), AggCode, 0 ))

 

 

Also I have a doubt that tDate[Last 13wks Flag] is indeed expected to be a boolean . If it’s actually a numeric format where 1 represents true, then the conversion would be different.


Proud to be a Power BI Super User !

Microsoft Community : https://docs.microsoft.com/en-us/users/AmiraBedhiafi
Linkedin : https://www.linkedin.com/in/amira-bedhiafi/
StackOverflow : https://stackoverflow.com/users/9517769/amira-bedhiafi
C-Sharp Corner : https://www.c-sharpcorner.com/members/amira-bedhiafi
Power BI Community :https://community.powerbi.com/t5/user/viewprofilepage/user-id/332696

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Thanks @AmiraBedh! I have converted the tDate [Last 13Wks Flag] to boolean getting easier to compare

 

AmiraBedh
Super User
Super User

If Last 13wks Flag is stored as text but actually represents a boolean, I think you'll need to properly convert this text to a numeric or boolean type that can be compared correctly. 

 

Week Accuracy (Last 13wks Flag) %:=VAR AggCode = Switch(
    True(),
    Max(tAccuracy[Aggregation Code]) = 2 && SWITCH(MAXA(tDate[Last 13wks Flag]), "TRUE", 1, "FALSE", 0, 0) = 1, [Week Product ID Location Accuracy %],
    Max(tAccuracy[Aggregation Code]) = 1 && SWITCH(MAXA(tDate[Last 13wks Flag]), "TRUE", 1, "FALSE", 0, 0) = 1, [Week Product Group Location Accuracy %],
    Max(tAccuracy[Aggregation Code]) = 0 && SWITCH(MAXA(tDate[Last 13wks Flag]), "TRUE", 1, "FALSE", 0, 0) = 1, [Week Product Group Accuracy %]
)
Return
IF ( AggCode > 1, 0, IF(AND ( AggCode <= 1, AggCode > 0 ), AggCode, 0 ))

 

 

Also I have a doubt that tDate[Last 13wks Flag] is indeed expected to be a boolean . If it’s actually a numeric format where 1 represents true, then the conversion would be different.


Proud to be a Power BI Super User !

Microsoft Community : https://docs.microsoft.com/en-us/users/AmiraBedhiafi
Linkedin : https://www.linkedin.com/in/amira-bedhiafi/
StackOverflow : https://stackoverflow.com/users/9517769/amira-bedhiafi
C-Sharp Corner : https://www.c-sharpcorner.com/members/amira-bedhiafi
Power BI Community :https://community.powerbi.com/t5/user/viewprofilepage/user-id/332696
ChiragGarg2512
Solution Sage
Solution Sage

It's either that [Aggregatiion Code] is text or [Last 13wks Flag] is an integer. 

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

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.