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
08152023
Frequent Visitor

Displaying latest data when data is equal to 0.

Hello, 

 

I am trying to pull the latest data (updated monthly) by calculating the MAX date where the "Actual" column is not blank. However, the issue arises when the latest data is equal to 0. PowerBI reads the latest data as the last row that does not contain 0. The following screenshot shows data through December 2023, with December = 0%. 

 

Screen Shot 2024-01-11 at 12.05.46 PM.png

The current DAX formula: 

 

Comm_Actual =
    VAR DateActual =
        CALCULATE(MAX('Communications Append'[Date]), 'Communications Append'[Actual]<>BLANK(),  
 
    VAR RecentActual =
        CALCULATE(SELECTEDVALUE('Communications Append'[Actual]), 'Communications Append'[Date] = DateActual)
    Return
    IF(AND(ISBLANK(RecentActual),NOT(ISBLANK('Communications Append'[Comm_Target]))),0,RecentActual)
 
Is there a way to rewrite the DAX formula so it pulls the latest data, including when the latest data is equal to 0?

1 ACCEPTED SOLUTION
amustafa
Super User
Super User

To address the issue where the latest data is equal to 0 and you want to consider it as the latest data instead of skipping it, you can modify your DAX formula to include zeros as well. The issue with your current formula is that it's using `SELECTEDVALUE` which will not consider a row with a 0 value as it is treated the same as BLANK by the filter `Actual <> BLANK()`.

Here's a revised version of the DAX formula that includes the 0 values as well:


Comm_Actual =
VAR MaxDateWithActual =
CALCULATE(MAX('Communications Append'[Date]), NOT(ISBLANK('Communications Append'[Actual])))
VAR RecentActual =
CALCULATE(SELECTEDVALUE('Communications Append'[Actual]), 'Communications Append'[Date] = MaxDateWithActual)
RETURN
IF(ISBLANK(RecentActual), 0, RecentActual)

In this version, `MaxDateWithActual` calculates the maximum date where the `Actual` column has any value, including 0. Then `RecentActual` gets the `Actual` value for that date. Finally, if `RecentActual` is BLANK (which shouldn't happen unless there's no data at all), it returns 0, otherwise, it returns the `Actual` value found.

Remember to replace `'Communications Append'` with the actual name of your table if it's different. This formula should work assuming that a 0 value is actually stored in the data and not just displayed as 0% while the underlying data is blank or null.





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

Proud to be a Super User!




View solution in original post

2 REPLIES 2
amustafa
Super User
Super User

To address the issue where the latest data is equal to 0 and you want to consider it as the latest data instead of skipping it, you can modify your DAX formula to include zeros as well. The issue with your current formula is that it's using `SELECTEDVALUE` which will not consider a row with a 0 value as it is treated the same as BLANK by the filter `Actual <> BLANK()`.

Here's a revised version of the DAX formula that includes the 0 values as well:


Comm_Actual =
VAR MaxDateWithActual =
CALCULATE(MAX('Communications Append'[Date]), NOT(ISBLANK('Communications Append'[Actual])))
VAR RecentActual =
CALCULATE(SELECTEDVALUE('Communications Append'[Actual]), 'Communications Append'[Date] = MaxDateWithActual)
RETURN
IF(ISBLANK(RecentActual), 0, RecentActual)

In this version, `MaxDateWithActual` calculates the maximum date where the `Actual` column has any value, including 0. Then `RecentActual` gets the `Actual` value for that date. Finally, if `RecentActual` is BLANK (which shouldn't happen unless there's no data at all), it returns 0, otherwise, it returns the `Actual` value found.

Remember to replace `'Communications Append'` with the actual name of your table if it's different. This formula should work assuming that a 0 value is actually stored in the data and not just displayed as 0% while the underlying data is blank or null.





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

Proud to be a Super User!




This worked perfectly! Thank you so much! This was a huge help! 

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! Prices go up Feb. 11th.

Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Jan NL Carousel

Fabric Community Update - January 2025

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