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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
salamekhamis
New Member

Help with DAX

I need help creating a measure for Total Amonut such that If I filter date by month for a certain loan and the total amount value is blank that month then I should get the value for the last nonblank month as shown:

salamekhamis_0-1742822832950.png

I should see this for December:

salamekhamis_1-1742822865507.png

 

Please help with the measure. I used this for Total Amount
Total Amount=Calculate(sum('loans'[Amount]))

2 ACCEPTED SOLUTIONS
andrewsommer
Super User
Super User

Try this:

Total Amount = 
VAR CurrentMonthAmount = SELECTEDVALUE('Table'[Amount])
VAR LastValidAmount = 
    CALCULATE(
        MAX('Table'[Amount]),
        'Table'[Amount] <> BLANK(),
        'Table'[Date] < MAX('Table'[Date])
    )
RETURN 
    IF(ISBLANK(CurrentMonthAmount), LastValidAmount, CurrentMonthAmount)

 

Please mark this post as solution if it helps you. Appreciate Kudos.

View solution in original post

v-ssriganesh
Community Support
Community Support

Hi @salamekhamis,
Thank you for bringing your query to the Microsoft Fabric Community Forum.

I have reproduced your scenario using my sample data, and I am sharing the steps, expected output screenshot and PBIX file for your reference.

  • Created a Date Table
DateTable =

ADDCOLUMNS (

    CALENDAR ( DATE ( 2025, 1, 1 ), DATE ( 2025, 12, 31 ) ),

    "MonthName", FORMAT ( [Date], "MMMM" )

)

Created a relationship between LoanData[Date] and DateTable[Date].

  • Created the Measure for Last Non-Blank Amount
LastNonBlankAmount = 
VAR LastAmount =
    CALCULATE(
        SUM(LoanData[Amount]),
        FILTER(
            ALL(LoanData),
            LoanData[Loan No] = SELECTEDVALUE(LoanData[Loan No]) &&
            LoanData[Date] <= MAX(LoanData[Date]) &&
            NOT(ISBLANK(LoanData[Amount])) 
        )
    )
RETURN LastAmount

This measure ensures that if a month has a blank amount, it fetches the last available non-blank value.

  • Below is the expected output screenshot:
    vssriganesh_0-1742923244106.png

     

If this is helpful, please “Accept it as a solution” and give a "kudos" to assist other community members in resolving similar issues more efficiently.
Thank you.

View solution in original post

5 REPLIES 5
v-ssriganesh
Community Support
Community Support

Hi @salamekhamis,
I wanted to check if you had the opportunity to review the information provided. Please feel free to contact us if you have any further questions. If my response has addressed your query, please accept it as a solution and give a 'Kudos' so other members can easily find it.
Thank you.

v-ssriganesh
Community Support
Community Support

Hi @salamekhamis,

May I ask if you have resolved this issue? If so, please mark the helpful reply and accept it as the solution. This will be helpful for other community members who have similar problems to solve it faster.

Thank you.

v-ssriganesh
Community Support
Community Support

Hi @salamekhamis,
Thank you for bringing your query to the Microsoft Fabric Community Forum.

I have reproduced your scenario using my sample data, and I am sharing the steps, expected output screenshot and PBIX file for your reference.

  • Created a Date Table
DateTable =

ADDCOLUMNS (

    CALENDAR ( DATE ( 2025, 1, 1 ), DATE ( 2025, 12, 31 ) ),

    "MonthName", FORMAT ( [Date], "MMMM" )

)

Created a relationship between LoanData[Date] and DateTable[Date].

  • Created the Measure for Last Non-Blank Amount
LastNonBlankAmount = 
VAR LastAmount =
    CALCULATE(
        SUM(LoanData[Amount]),
        FILTER(
            ALL(LoanData),
            LoanData[Loan No] = SELECTEDVALUE(LoanData[Loan No]) &&
            LoanData[Date] <= MAX(LoanData[Date]) &&
            NOT(ISBLANK(LoanData[Amount])) 
        )
    )
RETURN LastAmount

This measure ensures that if a month has a blank amount, it fetches the last available non-blank value.

  • Below is the expected output screenshot:
    vssriganesh_0-1742923244106.png

     

If this is helpful, please “Accept it as a solution” and give a "kudos" to assist other community members in resolving similar issues more efficiently.
Thank you.

Hi @salamekhamis,

I hope this information is helpful. Please let me know if you have any further questions or if you'd like to discuss this further. If this answers your question, please accept it as a solution and give it a 'Kudos' so other community members with similar problems can find a solution faster.
Thank you.

andrewsommer
Super User
Super User

Try this:

Total Amount = 
VAR CurrentMonthAmount = SELECTEDVALUE('Table'[Amount])
VAR LastValidAmount = 
    CALCULATE(
        MAX('Table'[Amount]),
        'Table'[Amount] <> BLANK(),
        'Table'[Date] < MAX('Table'[Date])
    )
RETURN 
    IF(ISBLANK(CurrentMonthAmount), LastValidAmount, CurrentMonthAmount)

 

Please mark this post as solution if it helps you. Appreciate Kudos.

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors