Forum Discussion
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:
My goal is the "Max_Min Color" column which should be contain only one value 0.0541.
Thank you in advanced!
- Anonymous2 years ago
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
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. Thank you very much!
7 Replies
- AnonymousNot 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.- TrongPhuocFrequent Visitor
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
- AnonymousNot 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
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.
- TrongPhuocFrequent Visitor
Hi Anonymous ,
I have tried your suggestion, but it didn't work like my expectation.
Here the results:
Is there anyway we can apply loop for this case?
Best regards,
TrongPhuoc
- AnonymousNot 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.
- TrongPhuocFrequent Visitor
Hi Anonymous ,
Here are sample data,
Date order1 order2 order3 CriticalVal 01-02-2024 1 1 1 0.03486 01-02-2024 1 1 2 0.034545 01-02-2024 1 1 3 0.034335 01-02-2024 1 2 1 0.02856 01-02-2024 1 2 2 0.02793 01-02-2024 1 2 3 0.027405 16-02-2024 1 1 1 0.039165 16-02-2024 1 1 2 0.03885 16-02-2024 1 1 3 0.03864 16-02-2024 1 2 1 0.032865 16-02-2024 1 2 2 0.03234 16-02-2024 1 2 3 0.03171 01-03-2024 1 1 1 0.04347 01-03-2024 1 1 2 0.043155 01-03-2024 1 1 3 0.04284 01-03-2024 1 2 1 0.03696 01-03-2024 1 2 2 0.036435 01-03-2024 1 2 3 0.035805 16-03-2024 1 1 1 0.04599 16-03-2024 1 1 2 0.045675 16-03-2024 1 1 3 0.04536 16-03-2024 1 2 1 0.03948 16-03-2024 1 2 2 0.038955 16-03-2024 1 2 3 0.038325 01-04-2024 1 1 1 0.04935 01-04-2024 1 1 2 0.049035 01-04-2024 1 1 3 0.04872 01-04-2024 1 2 1 0.04263 01-04-2024 1 2 2 0.042105 01-04-2024 1 2 3 0.041475 01-02-2024 2 3 1 0.034335 01-02-2024 2 3 2 0.03402 01-02-2024 2 3 3 0.03381 01-02-2024 2 4 1 0.028245 01-02-2024 2 4 2 0.027615 01-02-2024 2 4 3 0.02709 16-02-2024 2 3 1 0.038535 16-02-2024 2 3 2 0.03822 16-02-2024 2 3 3 0.037905 16-02-2024 2 4 1 0.03234 16-02-2024 2 4 2 0.031815 16-02-2024 2 4 3 0.031185 01-03-2024 2 3 1 0.042525 01-03-2024 2 3 2 0.04221 01-03-2024 2 3 3 0.041895 01-03-2024 2 4 1 0.036225 01-03-2024 2 4 2 0.035595 01-03-2024 2 4 3 0.03507 16-03-2024 2 3 1 0.04515 16-03-2024 2 3 2 0.04473 16-03-2024 2 3 3 0.044415 16-03-2024 2 4 1 0.03864 16-03-2024 2 4 2 0.03801 16-03-2024 2 4 3 0.037485 01-04-2024 2 3 1 0.048195 01-04-2024 2 3 2 0.04788 01-04-2024 2 3 3 0.047565 01-04-2024 2 4 1 0.04158 01-04-2024 2 4 2 0.041055 01-04-2024 2 4 3 0.040425 01-02-2024 3 5 1 0.031185 01-02-2024 3 5 2 0.03087 01-02-2024 3 5 3 0.03066 01-02-2024 3 6 1 0.025095 01-02-2024 3 6 2 0.024465 01-02-2024 3 6 3 0.02373 16-02-2024 3 5 1 0.03528 16-02-2024 3 5 2 0.03507 16-02-2024 3 5 3 0.034755 16-02-2024 3 6 1 0.029295 16-02-2024 3 6 2 0.02856 16-02-2024 3 6 3 0.02793 01-03-2024 3 5 1 0.039795 01-03-2024 3 5 2 0.03948 01-03-2024 3 5 3 0.039165 01-03-2024 3 6 1 0.03339 01-03-2024 3 6 2 0.03276 01-03-2024 3 6 3 0.032025 16-03-2024 3 5 1 0.04284 16-03-2024 3 5 2 0.042525 16-03-2024 3 5 3 0.042315 16-03-2024 3 6 1 0.036435 16-03-2024 3 6 2 0.0357 16-03-2024 3 6 3 0.034965 01-04-2024 3 5 1 0.04683 01-04-2024 3 5 2 0.04662 01-04-2024 3 5 3 0.0462 01-04-2024 3 6 1 0.040215 01-04-2024 3 6 2 0.03948 01-04-2024 3 6 3 0.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 expectationDate oder1st oder2nd order3rd CriticalValue MaxColor 01-04-2024 1 1 1 0.04935 Red 01-04-2024 1 1 2 0.049035 #118DFF 01-04-2024 1 1 3 0.04872 #118DFF 01-04-2024 1 2 1 0.04263 #118DFF 01-04-2024 1 2 2 0.042105 #118DFF 01-04-2024 1 2 3 0.041475 #118DFF Best regards,
TrongPhuoc
- TrongPhuocFrequent Visitor
Thank you very much!