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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
carlj
Frequent Visitor

PREVIOUSMONTH without looking into the future

Hi All,

 

I am a regular reader of this forum, but this is my first time posting a question.

 

I have a table that lists a count (of users) by month.

I created a measure 'Total Variance' that calculates the difference between a given month and the month before as below:

Total Variance = 
	sum('table'[total_count]) - CALCULATE(
		sum('table'[total_count]),
			PREVIOUSMONTH('table'[month].[Date]))
The table below, showing a subset of the data, shows that while the difference is calculated correctly it also calculates the difference for June 2019, essentially subtracting the figure for May from the (non-existant) June figure.
 
image.png
Is there a way to force this caculation to only go up to May, or whatever the max month is?
 
When displaying the data in table format I am able to exlude this last line by filtering out blank entries in the total_count column, but this doesn't work when visualizing the data as graph.
 
Thanks
1 ACCEPTED SOLUTION
v-cherch-msft
Employee
Employee

Hi @carlj 

You may try to add an IF condition in the formula.For example:

Total Variance =
IF (
    SUM ( 'table'[total_count] ) = BLANK (),
    BLANK (),
    SUM ( 'table'[total_count] )
        - CALCULATE (
            SUM ( 'table'[total_count] ),
            PREVIOUSMONTH ( 'table'[month].[Date] )
        )
)

Regards,

Community Support Team _ Cherie Chen
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
v-cherch-msft
Employee
Employee

Hi @carlj 

You may try to add an IF condition in the formula.For example:

Total Variance =
IF (
    SUM ( 'table'[total_count] ) = BLANK (),
    BLANK (),
    SUM ( 'table'[total_count] )
        - CALCULATE (
            SUM ( 'table'[total_count] ),
            PREVIOUSMONTH ( 'table'[month].[Date] )
        )
)

Regards,

Community Support Team _ Cherie Chen
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thanks @v-cherch-msft , this is perfect!

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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