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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
jimpatel
Post Patron
Post Patron

Dax formula

Hi,

 

Thanks for looking at my post.

I have below code and can you any one please point me how to modify this code for below logic please?

 

If there is no "Green" at all then i need comment as "Please Check"

 

Any idea please?

 

measure 2 =
VAR _mat = MAX('Operation description'[Merged1])
VAR _laststep =
MAXX(
FILTER(
ALL('Operation description'),
'Operation description'[STATUS] = "GREEN"
&& 'Operation description'[Merged1] = _mat
),
'Operation description'[Column 3]
)
VAR _result =
CALCULATE(
COUNTROWS(
FILTER(
ALL('Operation description'),
'Operation description'[Column 3] = _laststep
&& 'Operation description'[Merged1] = _mat
)
)
)
RETURN
IF(
MAX('Operation description'[Column 3]) = _laststep,
_result,
BLANK()
)
1 ACCEPTED SOLUTION

Glad to hear it worked. Try this updated DAX...

 

measure 2 =
VAR _mat = MAX('Operation description'[Merged1])
VAR _firstRed =
MINX(
FILTER(
ALL('Operation description'),
'Operation description'[STATUS] = "RED" &&
'Operation description'[Merged1] = _mat
),
'Operation description'[Column 3]
)
VAR _lastGreen =
MAXX(
FILTER(
ALL('Operation description'),
'Operation description'[STATUS] = "GREEN" &&
'Operation description'[Merged1] = _mat
),
'Operation description'[Column 3]
)
VAR _greenExists =
CALCULATE(
COUNTROWS(
FILTER(
ALL('Operation description'),
'Operation description'[STATUS] = "GREEN"
)
)
)
VAR _laststep = IF(_greenExists > 0, _lastGreen, _firstRed)
VAR _result =
CALCULATE(
COUNTROWS(
FILTER(
ALL('Operation description'),
'Operation description'[Column 3] = _laststep &&
'Operation description'[Merged1] = _mat
)
)
)
RETURN
IF(
MAX('Operation description'[Column 3]) = _laststep,
_result,
BLANK()
)

 

If I answered your question, please mark this thread as accepted.
Follow me on LinkedIn:
https://www.linkedin.com/in/mustafa-ali-70133451/





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

Proud to be a Super User!




View solution in original post

6 REPLIES 6
jimpatel
Post Patron
Post Patron

Much appreciated your help

 

Will check the possible issues and will come back to you

 

Thanks again

jimpatel
Post Patron
Post Patron

Much appreciated again for your time.

 

Unfortunately its not giving any solution and its showing blank for red 😞

 

Thanks 

Potential Issues and Solutions:

  • Data Mismatch: Ensure that the data in 'Operation description'[STATUS] is correctly labeled as "RED". Sometimes issues with case sensitivity or extra spaces can cause mismatches.

  • Filter Context: The use of ALL('Operation description') removes all filters from the 'Operation description' table. Verify that this is the intended behavior and that it's not causing unexpected results.

  • Logic in _laststep: If there are no "GREEN" statuses in your data, _laststep will be set to _firstRed. Ensure that _firstRed is computed correctly.

  • Checking Conditions: The final IF condition checks if the maximum of 'Operation description'[Column 3] is equal to _laststep. Verify that this condition is appropriate for your data and logic.

  • Data Availability: Ensure that there are rows in your data that meet the criteria set in your measure. If no rows meet these conditions, the measure would naturally return BLANK.





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

Proud to be a Super User!




jimpatel
Post Patron
Post Patron

Thanks a lot for your time and effort. It works perfectly fine. 

 

What if i need to do for one more logic please

 

1. If no green then take first red 

 

Thanks a lot and much appreciated your help

Glad to hear it worked. Try this updated DAX...

 

measure 2 =
VAR _mat = MAX('Operation description'[Merged1])
VAR _firstRed =
MINX(
FILTER(
ALL('Operation description'),
'Operation description'[STATUS] = "RED" &&
'Operation description'[Merged1] = _mat
),
'Operation description'[Column 3]
)
VAR _lastGreen =
MAXX(
FILTER(
ALL('Operation description'),
'Operation description'[STATUS] = "GREEN" &&
'Operation description'[Merged1] = _mat
),
'Operation description'[Column 3]
)
VAR _greenExists =
CALCULATE(
COUNTROWS(
FILTER(
ALL('Operation description'),
'Operation description'[STATUS] = "GREEN"
)
)
)
VAR _laststep = IF(_greenExists > 0, _lastGreen, _firstRed)
VAR _result =
CALCULATE(
COUNTROWS(
FILTER(
ALL('Operation description'),
'Operation description'[Column 3] = _laststep &&
'Operation description'[Merged1] = _mat
)
)
)
RETURN
IF(
MAX('Operation description'[Column 3]) = _laststep,
_result,
BLANK()
)

 

If I answered your question, please mark this thread as accepted.
Follow me on LinkedIn:
https://www.linkedin.com/in/mustafa-ali-70133451/





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

Proud to be a Super User!




amustafa
Solution Sage
Solution Sage

Try this please....

 

measure 2 =
VAR _mat = MAX('Operation description'[Merged1])
VAR _laststep =
MAXX(
FILTER(
ALL('Operation description'),
'Operation description'[STATUS] = "GREEN" &&
'Operation description'[Merged1] = _mat
),
'Operation description'[Column 3]
)
VAR _result =
CALCULATE(
COUNTROWS(
FILTER(
ALL('Operation description'),
'Operation description'[Column 3] = _laststep &&
'Operation description'[Merged1] = _mat
)
)
)
VAR _greenExists =
CALCULATE(
COUNTROWS(
FILTER(
ALL('Operation description'),
'Operation description'[STATUS] = "GREEN"
)
)
)
RETURN
IF(
_greenExists = 0,
"Please Check",
IF(
MAX('Operation description'[Column 3]) = _laststep,
_result,
BLANK()
)
)

 

 





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

Proud to be a Super User!




Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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