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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
Giada_Togliatti
Post Patron
Post Patron

problem with a dax formula

Hi,

I have a database like this: 

field1field2field3
0,4F2018
0,5F2019
0,6G2020

where field2 has a text format, field 1 is a number  and field3 is like a date but is in text format. 

I should make a formula like this one

Measure = IF([mea1]= "labels" OR [mea1]= "chairs", OR [mea1]= "tables",
CALCULATE (
MAX(field1),
field2="F",
field3= MAX(field3)
),
CALCULATE (
MAX(field1)*100 & "%",
field2="F",
field3= MAX(field3)
)
)
I have error at the beginning with the using of or and I have another error  after calculate that says that I can't compare value of type number with value of type text, how should I do to remove these errors?

Thank you

1 ACCEPTED SOLUTION
v-deddai1-msft
Community Support
Community Support

Hi @Giada_Togliatti ,

 

Would you please refer to the dax below:

 

 

 

Measure =
IF (
    [mea1] = "labels"
        || [mea1] = "chairs"
        || [mea1] = "tables",
    CALCULATE (
        MAX ( field1 ),
        FILTER ( table, field2 = "F" && field3 IN VALUES ( field3 ) )
    ),
    CALCULATE (
        MAX ( field1 ) * 100 & "%",
        FILTER ( table, field2 = "F" && field3 IN VALUES ( field3 ) )
    )
)

 

 

 

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

 

Best Regards,

Dedmon Dai

View solution in original post

9 REPLIES 9
v-deddai1-msft
Community Support
Community Support

Hi @Giada_Togliatti ,

 

Would you please refer to the dax below:

 

 

 

Measure =
IF (
    [mea1] = "labels"
        || [mea1] = "chairs"
        || [mea1] = "tables",
    CALCULATE (
        MAX ( field1 ),
        FILTER ( table, field2 = "F" && field3 IN VALUES ( field3 ) )
    ),
    CALCULATE (
        MAX ( field1 ) * 100 & "%",
        FILTER ( table, field2 = "F" && field3 IN VALUES ( field3 ) )
    )
)

 

 

 

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

 

Best Regards,

Dedmon Dai

@v-deddai1-msft thank you for the formula, but it doesn't work, there is always the problem with the max

Hi @Giada_Togliatti ,

 

I have modified my original reply, please try again.

 

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

 

Best Regards,

Dedmon Dai

FarhanAhmed
Community Champion
Community Champion

Instead of using "MAX(field1)*100 & "%" try use "FORMAT( max('Table'[Column1]),"Percent")"







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

Proud to be a Super User!




Pragati11
Super User
Super User

HI @Giada_Togliatti ,

 

You can't use OR. Replace it with || in the DAX expression as follows:

 

Measure = IF([mea1]= "labels" || [mea1]= "chairs" || [mea1]= "tables",
CALCULATE (
MAX(field1),
field2="F",
field3= MAX(field3)
),
CALCULATE (
MAX(field1)*100 & "%",
field2="F",
field3= MAX(field3)
)
)

 

Also, there was an extra comma (,) in the 1st line of your dax.

 

Thanks,

Pragati

Best Regards,

Pragati Jain


MVP logo


LinkedIn | Twitter | Blog YouTube 

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

Appreciate your Kudos!!

Proud to be a Super User!!

AllisonKennedy
Super User
Super User

You can use || for OR

Measure = IF([mea1]= "labels" || [mea1]= "chairs" || [mea1]= "tables",
CALCULATE (
MAX(field1),
field2="F",
field3= MAX(field3)
),
CALCULATE (
MAX(field1)*100 & "%",
field2="F",
field3= MAX(field3)
)
)

For the data type I think it's Field3 that's the problem as MAX is converting it to an integer and trying to compare to field3 as text, so you can use CONVERT function to change data type; https://docs.microsoft.com/en-us/dax/convert-function-dax

Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

thank you for reply,

I think the problem for field 3 is that it's a text and I compare with the maximum of a text

Measura prova max = CALCULATE(sum(field2), field3= max(field3))

it gives me error,

which formula can I use to have the right result and to covert the field3 in a number?

field 3 is like a date with text format (201806, 201906...)

 

FarhanAhmed
Community Champion
Community Champion

What is [mea1]?







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

Proud to be a Super User!




mea1 it's the maximum of a text field

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.