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
Sofinobi
Helper IV
Helper IV

if curent month is blank, return last month value

hello all,

please, i have a measure to calculate the average quantity in stock by month, the problem is when there is no transaction for a product in a month (on sales_tab) it doesn't give me any value, i want to give me the latest value 
here is my measure:

AVG Stock Qte Month = var _avgQte= AVERAGEX(Sales_Tab,Sales_Tab[OldLogicalQuantity])
                   return
                   if(isblank(_avgQte),
                       CALCULATE(
                           AverageX(Values('Date'[Month Year]), _avgQte),filter(all('Date'),'Date'[date] <=max('Date'[date]))), _avgQte)
averageifblanck.pbix 

in this image an exemple for the result needed
Capture6.PNG
thank you all
1 ACCEPTED SOLUTION
CNENFRNL
Community Champion
Community Champion

CNENFRNL_0-1675039770885.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

View solution in original post

3 REPLIES 3
tamerj1
Super User
Super User

Hi @Sofinobi 
If the added values shall be counted in the total, you may try this as per attached sample file.

1.png

Average Filldown = 
AVERAGEX (
    VALUES ( 'Date'[YearMonth Number] ),
    VAR CurrentMonth = 'Date'[YearMonth Number]
    VAR LastDateWithData = 
        MAXX ( 
            FILTER ( 
                CALCULATETABLE ( VALUES ( Sales_Tab[CreationDate] ), ALL ( 'Date' ) ),
                FORMAT ( Sales_Tab[CreationDate], "YYYYMM" ) <= CurrentMonth
            ),
            Sales_Tab[CreationDate]
        )
    VAR LastMonthWithData = FORMAT ( LastDateWithData, "YYYYMM" )
    RETURN
        CALCULATE ( 
            AVERAGE ( Sales_Tab[OldLogicalQuantity] ), 
            'Date'[YearMonth Number] = LastMonthWithData,
            ALL ( 'Date' )
        )
)

 

CNENFRNL
Community Champion
Community Champion

CNENFRNL_0-1675039770885.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

thank you my friend

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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