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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
2NV_DB
Frequent Visitor

Different result when using Measure as a variable vs using a scalar.

Hi there,

 

I have a dax measure that finds the last date within the exisiting year of a data set and then it extracts the month:

ThisMonthBasedOnInvoices = 
VAR _thisyear = YEAR(TODAY())

VAR _lastinvoicedate = LASTDATE(Consolidated_Sales_ActualTable[Sales_Invoice_date])

VAR _calculation = MONTH(CALCULATE(_lastinvoicedate,FILTER('Financial Calendar','Financial Calendar'[Year]=_thisyear)))

RETURN
_calculation

If I put this measure in a card, I get 5 (which is what I expected).

When I take this measure and use it in a filter of another measure like so:

IncrementalSales24 = 

CALCULATE(([SalesSum24]-[SalesSum23]),
FILTER('Financial Calendar','Financial Calendar'[Month Number]<=[ThisMonthBasedOnInvoices]

))


I get the following chart which is not what I want.

2NV_DB_0-1717636774154.png

If instead I use a scalar value of 5 like so, I get the chart I do want:

IncrementalSales24 = 

CALCULATE(([SalesSum24]-[SalesSum23]),
FILTER('Financial Calendar','Financial Calendar'[Month Number]<=5

))

2NV_DB_1-1717636838683.png

I would have expected both charts to be the same. Why is there a difference if the first measure equates to 5?

Essentially I am trying to hide months in my chart that do not yet have data.

Thank you



4 REPLIES 4
Devender_Power
New Member

The issue is that Lastdate is dynamic and because of it  it is not giving correct output try the below

 

ThisMonthBasedOnInvoices = 
VAR _thisyear = YEAR(TODAY())

VAR _lastinvoicedate = Calculate(LASTDATE(Consolidated_Sales_ActualTable[Sales_Invoice_date]),all(Consolidated_Sales_ActualTable))

VAR _calculation = MONTH(_lastinvoicedate)

RETURN
_calculation

 

Best Regards

Devender Kumar

If this helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

2NV_DB
Frequent Visitor

Any other suggestions?

Jihwan_Kim
Super User
Super User

Hi,

In my opinion, it is because of context transition when using [measure] inside CALCULATE DAX function.

Row context -> Filter context

CALCULATE function (DAX) - DAX | Microsoft Learn


Please try something like below whether it suits your requirement.

 

IncrementalSales24 =
VAR _condition = [ThisMonthBasedOnInvoices]
VAR _result =
    CALCULATE (
        ( [SalesSum24] - [SalesSum23] ),
        FILTER (
            'Financial Calendar',
            'Financial Calendar'[Month Number] <= _condition
        )
    )
RETURN
    _result

 



Microsoft MVP



If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.




LinkedInVisit my LinkedIn page




Outlook BookingSchedule a short Teams meeting to discuss your question



Thanks for the reply but unfortunately that doesn't work either.
The chart looks like this:

2NV_DB_0-1717652547136.png

The _condition returns 5 as well.

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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