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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
kitti
Helper III
Helper III

Measure to display value based on amount conditions

Hello Experts,

 

Could you help me design a DAX measure for displaying value based on conditions like:

 

(By selected date)

The measure will display "GREEN" if:

  - RESULT is "pass"

The measure will display "RED" if:

  - RESULT is "fail" and is the first time (from the selected dated).

  - RESULT is "fail" after continuously 9 times of pass.

The measure will display "BLUE" if:

  - RESULT is "fail" before continuously 9 times of pass.

 

For example from day 1 - 15, if day 1 was pass then the measure showed GREEN, after that day 3 was fail then showed RED (first time failed) and then had a continuous pass (GREEN) until day 13 was fail (RED, after continuously day 4-12 passes). Lastly, day 14 was pass then it was GREEN but day 15 was fail so the measure displayed BLUE.

 

 

The data looks like this below:   (MEASURE_COLOUR is the measure I want)

PARAM_TESTMEASUREMENT_DATERESULTMEASURE_COLOUR
AB1/10/2022passGREEN
AB2/10/2022passGREEN
AB3/10/2022failRED
AB4/10/2022passGREEN
AB5/10/2022passGREEN
AB6/10/2022passGREEN
AB7/10/2022passGREEN
AB8/10/2022passGREEN
AB9/10/2022passGREEN
AB10/10/2022passGREEN
AB11/10/2022passGREEN
AB12/10/2022passGREEN
AB13/10/2022failRED
AB14/10/2022passGREEN
AB15/10/2022failBLUE

 

 

I truly appreciate any suggestions

KL

7 REPLIES 7
kitti
Helper III
Helper III

This is what I just tried but not correct just yet. Could anyone help

 

Measure =
VAR first_fail_date = CALCULATE( MIN(Sheet1[MEASUREMENT_DATE]), FILTER(Sheet1,Sheet1[RESULT]="fail"))
VAR count_fail_date = CALCULATE( COUNT(Sheet1[MEASUREMENT_DATE]), FILTER(Sheet1,Sheet1[RESULT]="fail"))

return
IF( SELECTEDVALUE(Sheet1[MEASURE_DATE]) = first_fail_date || count_fail_date > 9 , "RED", IF(count_fail_date < 9, "BLUE","GREEN"))

DimaMD
Solution Sage
Solution Sage

Hello @kitti  try 

Measure = 
VAR maxdata =CALCULATE( MAX('Таблиця'[MEASUREMENT_DATE]), ALL('Таблиця'))
return
IF( maxdata = MAX('Таблиця'[MEASUREMENT_DATE]), "blue", IF( SELECTEDVALUE('Таблиця'[RESULT]) = "pass", "green","red"))


Screenshot_26.jpg


__________________________________________

Thank you for your like and decision

__________________________________________

Greetings from Ukraine

To help me grow PayPal: embirddima@gmail.com

@DimaMD  Thank you for your reply.

 

But, I didn't see the conditions about this:

The measure will display "GREEN" if:

  - RESULT is "pass"

The measure will display "RED" if:

  - RESULT is "fail" and is the first time (from the selected dated).

  - RESULT is "fail" after continuously 9 times of pass.

The measure will display "BLUE" if:

  - RESULT is "fail" before continuously 9 times of pass.

 

P.S. The actual data now has more than 3 months.

@kitti Hi, Can you provide more detailed data, for example, for 2 months?


__________________________________________

Thank you for your like and decision

__________________________________________

Greetings from Ukraine

To help me grow PayPal: embirddima@gmail.com

@DimaMD 

This is the sample:

 

PARAM_TESTMEASUREMENT_DATERESULT
AB1/10/2022pass
AB2/10/2022pass
AB3/10/2022fail
AB4/10/2022pass
AB5/10/2022pass
AB6/10/2022pass
AB7/10/2022pass
AB8/10/2022pass
AB9/10/2022pass
AB10/10/2022pass
AB11/10/2022pass
AB12/10/2022pass
AB13/10/2022fail
AB14/10/2022pass
AB15/10/2022fail
AB16/10/2022fail
AB17/10/2022pass
AB18/10/2022fail
AB19/10/2022pass
AB20/10/2022fail
AB21/10/2022pass
AB22/10/2022pass
AB23/10/2022pass
AB24/10/2022pass
AB25/10/2022pass
AB26/10/2022pass
ACB17/10/2022pass
ACB18/10/2022pass
ACB24/10/2022pass
ACB25/10/2022pass
ACB27/10/2022pass
ACB28/10/2022fail
ACB30/10/2022pass
ACB31/10/2022pass
ACB1/11/2022pass
ACB2/11/2022pass
ADB2/11/2022pass
ADB3/11/2022pass
ADB4/11/2022pass
ADB5/11/2022fail
ADB6/11/2022pass
ADB7/11/2022fail
ADB8/11/2022pass
ADB9/11/2022pass
ADB10/11/2022pass
ADB11/11/2022pass
ADB12/11/2022pass
ADB13/11/2022pass
ADB14/11/2022pass
ADB15/11/2022pass
ADB16/11/2022pass
ADB17/11/2022pass
ADB18/11/2022pass
ADB19/11/2022pass
ADB20/11/2022pass
ADB21/11/2022fail
ADB22/11/2022pass
ADB23/11/2022pass
ADB24/11/2022pass

 

 

Thank you very much

KL

hi @kitti 

try to add a column with this:

 

Tag = 
VAR _date = [Date]
VAR _test = [TEST]
VAR _list =
CALCULATETABLE(
    data,
    ALLEXCEPT(data, data[Date],data[TEST]),
    data[Date]<_date+9,
    data[Date]>=_date+1
)
VAR _list2 =
CALCULATETABLE(
    DISTINCT(data[RESULT]),
    ALLEXCEPT(data, data[Date],data[TEST]),
    data[Date]<_date+9,
    data[Date]>=_date+1
)
RETURN
IF(
    [RESULT] = "PASS",
    "GREEN",
    IF(        
        NOT "Fail" in _list2 && COUNTROWS(_list) = 8,
        "BLUE",
        "RED"
    )
)

Hope it get what you expect:

FreemanZ_0-1672237973110.png

 

p.s. if you need further suggestion on this topic, please consider @me. 

 

@FreemanZ Thank you very much for your help. I just tried it, however, it seems hangs as it's being stuck at Working on it even though I already tested with 1-month data.

The table now has around 300k rows (3-month data) indeed. Can we fine tune the DAX?

 

 

Thank you,

KL

 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.