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
daviddavidson
Regular Visitor

Compare monthly amounts to the first month selected

 

 

 have years of data for telecom charges with an accounting date.

 

The Month to Month quick measure is almost what I want, but not quite.  I have modified it below to return the $ value instead of the percentage.  The problem is the Previous month is always -1 and I either need it to be fixed on the base month. or increment, like -1 then -2 then -3 etc.

 

For example if I choose all of 2021 I want the previous month calculation to always be January while the current month cycles through all of the months.

 

Also the range will be user selected so the first month could be any month and the duration could be any length.

Any ideas?

 

Savings =
IF(
    ISFILTERED('Telecom wireline all years'[Accounting Period]),
    ERROR("Time intelligence quick measures can only be grouped or filtered by the Power BI-provided date hierarchy or primary date column."),
    VAR __PREV_MONTH =
        CALCULATE(
            SUM('Telecom wireline all years'[Distribution Amount]),
            DATEADD('Telecom wireline all years'[Accounting Period].[Date], -1, MONTH
            )
        )
    RETURN
            SUM('Telecom wireline all years'[Distribution Amount]) - __PREV_MONTH
)
2 ACCEPTED SOLUTIONS
amitchandak
Super User
Super User

@daviddavidson , Try measure like

 

First Month of Year =
var _max1 = eomonth(if(isfiltered('Date'),MAX( 'Date'[Date]) , today()),0)
var _min = eomonth(_max,-1*month(_max1) )+1

var _max = eomonth(_min,0)
return
CALCULATE([net] ,DATESBETWEEN('Date'[Date],_min,_max))

 

This Month =
var _max = eomonth(if(isfiltered('Date'),MAX( 'Date'[Date]) , today()),0)
var _min = eomonth(_max,-1)+1 ,
return
CALCULATE([net] ,DATESBETWEEN('Date'[Date],_min,_max))

 

LMTD =
var _max1 = if(isfiltered('Date'),MAX( 'Date'[Date]) , today())
var _max = date(Year(_max1), month(_max1)-1, day(_max))
var _min = eomonth(_max1,-2)+1
return
CALCULATE([net] ,DATESBETWEEN('Date'[Date],_min,_max))

 

Last Month =
var _max1 = if(isfiltered('Date'),MAX( 'Date'[Date]) , today())
var _max = eomonth(_max1,-1)
var _min = eomonth(_max1,-2)+1
return
CALCULATE([net] ,DATESBETWEEN('Date'[Date],_min,_max))

 

https://medium.com/chandakamit/power-bi-when-i-felt-lazy-and-i-needed-too-many-measures-ed8de20d9f79

View solution in original post

v-yalanwu-msft
Community Support
Community Support

Hi,  @daviddavidson ;

Try it.

Measure = 
var _min= CALCULATE(MIN('Telecom wireline all years'[Accounting Period]),ALLSELECTED('Telecom wireline all years'))
return 
SUM([Distribution Amount])-
CALCULATE(SUM('Telecom wireline all years'[Distribution Amount]),FILTER(ALL('Telecom wireline all years'),EOMONTH([Accounting Period],0)=EOMONTH(_min,0)))

The final show:

vyalanwumsft_0-1666687692781.png


Best Regards,
Community Support Team _ Yalan Wu
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

3 REPLIES 3
v-yalanwu-msft
Community Support
Community Support

Hi,  @daviddavidson ;

Try it.

Measure = 
var _min= CALCULATE(MIN('Telecom wireline all years'[Accounting Period]),ALLSELECTED('Telecom wireline all years'))
return 
SUM([Distribution Amount])-
CALCULATE(SUM('Telecom wireline all years'[Distribution Amount]),FILTER(ALL('Telecom wireline all years'),EOMONTH([Accounting Period],0)=EOMONTH(_min,0)))

The final show:

vyalanwumsft_0-1666687692781.png


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

Yalan Wu,

Thanks this did most of what I needed.  I used ALLEXCEPT instead of ALL to keep some of the filters.  I appreciate the help.

amitchandak
Super User
Super User

@daviddavidson , Try measure like

 

First Month of Year =
var _max1 = eomonth(if(isfiltered('Date'),MAX( 'Date'[Date]) , today()),0)
var _min = eomonth(_max,-1*month(_max1) )+1

var _max = eomonth(_min,0)
return
CALCULATE([net] ,DATESBETWEEN('Date'[Date],_min,_max))

 

This Month =
var _max = eomonth(if(isfiltered('Date'),MAX( 'Date'[Date]) , today()),0)
var _min = eomonth(_max,-1)+1 ,
return
CALCULATE([net] ,DATESBETWEEN('Date'[Date],_min,_max))

 

LMTD =
var _max1 = if(isfiltered('Date'),MAX( 'Date'[Date]) , today())
var _max = date(Year(_max1), month(_max1)-1, day(_max))
var _min = eomonth(_max1,-2)+1
return
CALCULATE([net] ,DATESBETWEEN('Date'[Date],_min,_max))

 

Last Month =
var _max1 = if(isfiltered('Date'),MAX( 'Date'[Date]) , today())
var _max = eomonth(_max1,-1)
var _min = eomonth(_max1,-2)+1
return
CALCULATE([net] ,DATESBETWEEN('Date'[Date],_min,_max))

 

https://medium.com/chandakamit/power-bi-when-i-felt-lazy-and-i-needed-too-many-measures-ed8de20d9f79

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.