cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
rammishra
Helper I
Helper I

Need help to calculate measure that uses latest non-missing values

Dear Community Members

 

Apologies for multiple posts related to this topic.

 

Please help me in solving a problem that looks simple, but I am stuck with it. I am calculating a measure (a score) using the values of indicators for my states. My report has a slicer where users will choose a year to get the score for that particular year. In my data, year is entered as text in the form of: 2011-12, 2015-16, 2016-17, etc.

 

The measure works well as long as we have data for the indicator in the selected year. If the indicator values are missing for the selected year, my measure is missing for that year too. What I want is that my measure should include the most recent value of the indicator in case the indicator is missing for the selected year. For instance, if user selects 2016-17 the indicator has values only till 2015-16, then the measure should consider the value for 2015-16 to calculate the score.  Following is the DAX code for my measure (sample data are attached). 

 

I am not able to include additional DAX commands in following codes to check for whether the values of the indicators are missing for the selected year. If yes, then the measure should calculate the variables (x and minvalue) based on latest non-missing values. 

 

Test measure =
VAR x =
CALCULATE (
MAX ( Data[Value] ),
FILTER (
ALLEXCEPT ( Data, Data[State], Data[Year] ),
Data[Indicator No.] = "4.5.2"
)
)
VAR minvalue =
CALCULATE (
MIN ( Data[Value] ),
FILTER ( ALLEXCEPT ( Data, Data[Year] ), Data[Indicator No.] = "4.5.2" )
)
VAR num = ( x - minvalue )
VAR denom = ( 1 - minvalue )
RETURN
DIVIDE ( num, denom )
 
test data.JPG
1 ACCEPTED SOLUTION
tex628
Community Champion
Community Champion

Your example resulted in a divide by 0 so i changed the "1" in your sample data to a "1.11".

Take a look at the attached file.

I've added a numeric column that refers to year that you can use to refer to the most recent year with a score. 

Let me know if you have any questions! 


/ J


Connect on LinkedIn

View solution in original post

4 REPLIES 4
v-lionel-msft
Community Support
Community Support

Hi @rammishra ,

 

Like this?

Measure = 
VAR x = SUM(Data[Value])
RETURN
IF(
    x = BLANK(),
    CALCULATE(
        SUM(Data[Value]),
        FILTER(
            ALL(Data),
            Data[Indicator No.] = MAX(Data[Indicator No.]) && Data[YearNum] = MAX(Data[YearNum]) -1 && Data[State] = MAX(Data[State])
        )
    ),
    SUM(Data[Value])
)

v-lionel-msft_0-1599467579348.png

 

Best regards,
Lionel Chen

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

amitchandak
Super User
Super User

@rammishra , if not resolved with the last update.Can you share sample data and sample output in table format?



Features || Datamarts: https://youtu.be/8tskWsJTEpg || Field Parameters : https://youtu.be/lqF3Wa1FllE?t=70
Learn Power BI P&L Statement || Time Intelligence Decoded : https://youtu.be/aU2aKbnHuWs&t=145s ||
Did I answer your question? Mark my post as a solution! Appreciate your Kudos !! Proud to be a Super User! !!
Dashboard of My Blogs !! Connect on Linkedin !! Subscribe to my youtube Channel !!!! How to get Quick Help !!
Resources | Master Power BI !! Expertise Power BI !! Power BI For Tableau User !!
tex628
Community Champion
Community Champion

Your example resulted in a divide by 0 so i changed the "1" in your sample data to a "1.11".

Take a look at the attached file.

I've added a numeric column that refers to year that you can use to refer to the most recent year with a score. 

Let me know if you have any questions! 


/ J


Connect on LinkedIn

Thanks. This was really helpful. I only had to edit it by replacing "All" by "AllExcept" function. This is because, use of "All" resulted in same value of the measures across states.

 

Thank you, once again for your suggestions. This was the solution, I was looking for.

 

Cheers,

 

Ram

 

 

Helpful resources

Announcements
November 2022 Update

Check it Out!

Click here to read more about the November 2022 updates!

European Share Point Conference

European Share Point Conference

This conference returns live and in-person in Copenhagen this 28 November-01 December with 4 Microsoft Keynotes, 9 Tutorials, and 120 Sessions.

Microsoft 365 Conference â__ December 6-8, 2022

Microsoft 365 Conference - 06-08 December

Join us in Las Vegas to experience community, incredible learning opportunities, and connections that will help grow skills, know-how, and more.