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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors