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! Request now

Reply
TrongPhuoc
Frequent Visitor

Problem with IF DAX Funtion!

Hi everyone, I just give a try with a lated version of PowerBI Deskop

 

I met a weird situation, can anyone explain it to me?

I have a max value =0.0541, and I just want to create a color code for a row that contains the max value.

Here is my DAX:

 

 

 

GetMaxValue = MaXX(sn_test_data, CALCULATE(SUM(sn_test_data[Max creep_damage]),sn_test_data[Date]=Max(sn_test_data[Date])))

 

 

 

 

 

 

 

Max_Min Color = IF(
    SUM(sn_test_data[Max cr_damage]) = [GetMaxValue],[GetMaxValue],"#118DFF"
)

 

 

 

Here is the result that is not what I want:

 IF_error.png

 My goal is the "Max_Min Color" column which should be contain only one value 0.0541.

 

Thank you in advanced!

2 ACCEPTED SOLUTIONS
Anonymous
Not applicable

Hi @TrongPhuoc ,

Please try below steps:

1. create measure with below dax formula

Measure =
VAR max_date =
    MAXX ( ALL ( 'Table' ), 'Table'[Date] )
VAR tmp =
    FILTER ( ALL ( 'Table' ), 'Table'[Date] = max_date )
VAR max_val =
    MAXX ( tmp, [CriticalVal] )
VAR _a =
    CALCULATETABLE (
        VALUES ( 'Table'[order1] ),
        FILTER ( tmp, [CriticalVal] = max_val )
    )
VAR cur_date =
    SELECTEDVALUE ( 'Table'[Date] )
VAR cur_order =
    SELECTEDVALUE ( 'Table'[order1] )
RETURN
    IF ( AND ( cur_date = max_date, cur_order IN _a ), 1 )
Measure 2 =
VAR max_date =
    MAXX ( ALL ( 'Table' ), 'Table'[Date] )
VAR tmp =
    FILTER ( ALL ( 'Table' ), 'Table'[Date] = max_date )
VAR max_val =
    MAXX ( tmp, [CriticalVal] )
RETURN
    IF ( MAX ( 'Table'[CriticalVal] ) = max_val, "red" )

2. add table visual with fields

 

3. set visual level filter and conditional format for font color

vbinbinyumsft_0-1717128133051.png

 

Please refer the attached .pbix file.

 

Best regards,
Community Support Team_Binbin Yu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

TrongPhuoc
Frequent Visitor

Thank you very much!

View solution in original post

7 REPLIES 7
TrongPhuoc
Frequent Visitor

Thank you very much!

TrongPhuoc
Frequent Visitor

Hi @Anonymous ,

Here are sample data,

Dateorder1order2order3CriticalVal
01-02-20241110.03486
01-02-20241120.034545
01-02-20241130.034335
01-02-20241210.02856
01-02-20241220.02793
01-02-20241230.027405
16-02-20241110.039165
16-02-20241120.03885
16-02-20241130.03864
16-02-20241210.032865
16-02-20241220.03234
16-02-20241230.03171
01-03-20241110.04347
01-03-20241120.043155
01-03-20241130.04284
01-03-20241210.03696
01-03-20241220.036435
01-03-20241230.035805
16-03-20241110.04599
16-03-20241120.045675
16-03-20241130.04536
16-03-20241210.03948
16-03-20241220.038955
16-03-20241230.038325
01-04-20241110.04935
01-04-20241120.049035
01-04-20241130.04872
01-04-20241210.04263
01-04-20241220.042105
01-04-20241230.041475
01-02-20242310.034335
01-02-20242320.03402
01-02-20242330.03381
01-02-20242410.028245
01-02-20242420.027615
01-02-20242430.02709
16-02-20242310.038535
16-02-20242320.03822
16-02-20242330.037905
16-02-20242410.03234
16-02-20242420.031815
16-02-20242430.031185
01-03-20242310.042525
01-03-20242320.04221
01-03-20242330.041895
01-03-20242410.036225
01-03-20242420.035595
01-03-20242430.03507
16-03-20242310.04515
16-03-20242320.04473
16-03-20242330.044415
16-03-20242410.03864
16-03-20242420.03801
16-03-20242430.037485
01-04-20242310.048195
01-04-20242320.04788
01-04-20242330.047565
01-04-20242410.04158
01-04-20242420.041055
01-04-20242430.040425
01-02-20243510.031185
01-02-20243520.03087
01-02-20243530.03066
01-02-20243610.025095
01-02-20243620.024465
01-02-20243630.02373
16-02-20243510.03528
16-02-20243520.03507
16-02-20243530.034755
16-02-20243610.029295
16-02-20243620.02856
16-02-20243630.02793
01-03-20243510.039795
01-03-20243520.03948
01-03-20243530.039165
01-03-20243610.03339
01-03-20243620.03276
01-03-20243630.032025
16-03-20243510.04284
16-03-20243520.042525
16-03-20243530.042315
16-03-20243610.036435
16-03-20243620.0357
16-03-20243630.034965
01-04-20243510.04683
01-04-20243520.04662
01-04-20243530.0462
01-04-20243610.040215
01-04-20243620.03948
01-04-20243630.038745

 

My ultimate goal is to highlight just 1 cell off column "CriticalVal" that contain max value in Table visual by creating another column by DAX for example "MaxColor". I also add some filter by Slicer visual to get last "Date" and "order1"=1. 
Here is my expectation

Dateoder1stoder2ndorder3rdCriticalValueMaxColor
01-04-20241110.04935Red
01-04-20241120.049035#118DFF
01-04-20241130.04872#118DFF
01-04-20241210.04263#118DFF
01-04-20241220.042105#118DFF
01-04-20241230.041475#118DFF

 

Best regards,

TrongPhuoc
   

TrongPhuoc
Frequent Visitor

Hi @Anonymous ,

I have tried your suggestion, but it didn't work like my expectation.

Here the results:
IF_error2.png

 Is there anyway we can apply loop for this case?

Best regards,

TrongPhuoc

Anonymous
Not applicable

Hi @TrongPhuoc ,

In order to better understand your demands and give the right solution, could you please provide some more specific information? such as your desensitized example data and a screenshot of your desired results?

 

Thanks for your efforts & time in advance.

 

Best regards,
Community Support Team_Binbin Yu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

Hi @TrongPhuoc ,

Please try to adjust your dax formula with below dax formula:

Max_Min Color = IF(
    selectedvalue(sn_test_data[Max cr_damage]) = [GetMaxValue],[GetMaxValue],"#118DFF"
)

 

Best regards,
Community Support Team_Binbin Yu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi @Anonymous ,

Is it possible to execute my idea by using dax? It've been a while when I sent you my sample!
Best regards,

Trong-Phuoc Huynh

Anonymous
Not applicable

Hi @TrongPhuoc ,

Please try below steps:

1. create measure with below dax formula

Measure =
VAR max_date =
    MAXX ( ALL ( 'Table' ), 'Table'[Date] )
VAR tmp =
    FILTER ( ALL ( 'Table' ), 'Table'[Date] = max_date )
VAR max_val =
    MAXX ( tmp, [CriticalVal] )
VAR _a =
    CALCULATETABLE (
        VALUES ( 'Table'[order1] ),
        FILTER ( tmp, [CriticalVal] = max_val )
    )
VAR cur_date =
    SELECTEDVALUE ( 'Table'[Date] )
VAR cur_order =
    SELECTEDVALUE ( 'Table'[order1] )
RETURN
    IF ( AND ( cur_date = max_date, cur_order IN _a ), 1 )
Measure 2 =
VAR max_date =
    MAXX ( ALL ( 'Table' ), 'Table'[Date] )
VAR tmp =
    FILTER ( ALL ( 'Table' ), 'Table'[Date] = max_date )
VAR max_val =
    MAXX ( tmp, [CriticalVal] )
RETURN
    IF ( MAX ( 'Table'[CriticalVal] ) = max_val, "red" )

2. add table visual with fields

 

3. set visual level filter and conditional format for font color

vbinbinyumsft_0-1717128133051.png

 

Please refer the attached .pbix file.

 

Best regards,
Community Support Team_Binbin Yu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

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!

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.

Top Solution Authors