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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
jessicarocha
Helper IV
Helper IV

Return as aggregation of a conditional measure the result for the last completed week

Hello, 

 

I have a formula that calculates the inventory turn ratio. But there is no aggregation displayed.

 

 

Ratio = 
IF(
    MAX( dim_date[date_id] )  < TODAY(),
    VAR __wdw =
        WINDOW( -51, REL, 0, REL, ALLSELECTED( dim_date[week] ), ORDERBY( dim_date[week] ) )
    RETURN
        IF(
            COUNTROWS( __wdw ) = 52,
            CALCULATE( [sum_demand] / [avg_stock], __wdw )
        )
)

 

I would like to see as an aggregation, the value of the formula for the most recent week that contains data. In this example, I would like to see 7.67 as an aggregation. Even if the user doesn't have any variable from the date dimension in a table or card, I still would like to see the 7.67.

jessicarocha_0-1724747266870.png

 

Can you help me to modify the formula to achieve this?
Dummy Power BI file is available in the following link: 

Link dummy PB 

Thank you. 

1 ACCEPTED SOLUTION
HotChilli
Super User
Super User

I think you can get this with LASTNONBLANKVALUE.

Create another measure using this and pass the [Ratio] measure to it.

View solution in original post

5 REPLIES 5
HotChilli
Super User
Super User

The original measure is explicitly checking for 52 rows in the window.  There aren't 52 rows in the context of the card so you get a blank returned.

jessicarocha
Helper IV
Helper IV

@HotChilli you are right, it works for the card visual. Thank you so much for the help! 

 

jessicarocha_0-1724827177248.png

But I still don't get an aggregation in the end of the table. 

I wanted to have the last value as the default aggregation, but if the user selected a specific week, then this value should be displayed. At the moment, if the user filter a different week, the result is empty. Do you know if there is a way to achieve this?

jessicarocha_1-1724827280813.png

 

HotChilli
Super User
Super User

"it doesn't work. I think the argument has to be a column" - there are 2 arguments, one is a column, one is an expression. I think it works.

If you are writing DAX as per the measure you posted, you can solve this one. 

HotChilli
Super User
Super User

I think you can get this with LASTNONBLANKVALUE.

Create another measure using this and pass the [Ratio] measure to it.

@HotChilli it doesn't work. I think the argument has to be a column...
I have a power BI dummy file as a link available for download in the post, in case you want to try

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!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

Feb2025 NL Carousel

Fabric Community Update - February 2025

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