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

Get inspired! Check out the entries from the Power BI DataViz World Championships preliminary rounds and give kudos to your favorites. View the vizzies.

Reply
vijay273162
Helper III
Helper III

Cumulative DAX affecting filter context used in Custom Measure

Hi All,

Below is my Code for Cumulative Sales, used on top of Custom_Sales variable

 

VAR Forecast_CY-Q =
CALCULATE ( [Forecast Value],
           REMOVEFILTERS (Calendar [Running Days]) ---- I need to use removefilter.
)

VAR Custom_Sales =
IF ( Calendar [ Date ] < today(),
        [Sales_PY-Q] + Forecast_CY-Q ,
        [Sales_CY-Q]
)

VAR QTD_CY =
CALCULATE (
     SUMX (
                 SUMMARIZE ( Calendar, Calendar[Running Days], “@Custom Sales”, Custom_Sales
                ), [@Custom Sales],
      FILTER ( ALLSELECTED ( Calendar),
                  Calendar [Running Days] <= MAX ( Calendar [Running Days]
      )


Return
QTD_CY

 

------ This QTD_CY is not returning expected result, after today (values are higher)
------ It Seems using variable - Forecast_CY-Q filter context fails when used in cumulative calculation.

 

How to write cumulative calculation, without affecting the filter context used in custom Measures ?

1 ACCEPTED SOLUTION
vijay273162
Helper III
Helper III

Thanks for your explanation about variable.

 

I have fixed the issue now, after some research. 

can you please look at this :........ link : 

Solved: Re: Calendar Table help - Microsoft Power BI Community 

it is open, since my solution is not best.

View solution in original post

2 REPLIES 2
vijay273162
Helper III
Helper III

Thanks for your explanation about variable.

 

I have fixed the issue now, after some research. 

can you please look at this :........ link : 

Solved: Re: Calendar Table help - Microsoft Power BI Community 

it is open, since my solution is not best.

v-jingzhang
Community Support
Community Support

Hi @vijay273162 

 

Variables are only evaluated once. After it is evaluated in its definition code, it behaves like a static value in other DAX expression. In your measure, Custom_Sales has calculated a value. When it's used in the cumulative expression of QTD_CY, the static value is summarized for every running day. It means it returns the static value for every running day in the table returned by SUMMARIZE function. 

 

Currently the expected output is not clear. Can you please provide some mock data to show the table you have and what expected result should be like? We need to modify your measure or create a new measure based on the mock data and expected output. 

 

Best Regards,
Community Support Team _ Jing

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 FABINSIDER for a $400 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

March2025 Carousel

Fabric Community Update - March 2025

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