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

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

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
Community Champion
Community Champion

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
Community Champion
Community Champion

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
Community Champion
Community Champion

"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
Community Champion
Community Champion

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
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.