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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Connerf
Frequent Visitor

Month to Go Calculation

Hey Power BI Team,

 

I'm looking for a bit of help regarding a month to go (MTG (no not magic the gathering)) calculation. The calculation needs to accomplish the following three things:

 

  1. Return a BLANK() for any values < TODAY()
  2. Return [Total Schedule] for only the days remaining in the month
  3. Return [Total Schedule] for months beyond the current month

(I've figured out 2/3 items above)

 

Sample Data:

DATE(DimDate)  Total Schedule(Fact Schedule)

2019-05-01         100

...

2019-05-30         100

2019-05-31         100

 

For May 2019, the [MTG Schedule] needs to = 200. However, for dates in June and beyond, it should return the [Total Schedule].

 

Current Code:

MTG Production = 

var maxDate = EOMONTH(TODAY(), 0)

RETURN

CALCULATE(
    [Total Schedule],
    FILTER(
        'Date', 'Date'[Date] >= TODAY() && 'Date'[Date] <= maxDate
    )
)

For whatever reason, I can't figure out how to wrap the above calculation in an IF statement that would just return [Total Schedule] when the MONTH([Date[Date]) > MONTH(TODAY()).

 

Thanks for your help.

1 ACCEPTED SOLUTION

@Connerf 

Ok, try this slight change then. Remember to always show an example based on your data to explain what you need. It is very helpful for those trying to provide an answer

TG Production =
VAR maxDate =
    IF (
        MONTH ( TODAY () ) = MONTH ( MAX('Date'[Date] )),
        EOMONTH ( TODAY (), 0 ),
        MAX ( 'Date'[Date] )
    )
RETURN
    CALCULATE (
        [Total Schedule],
        FILTER ( 'Date', 'Date'[Date] >= TODAY () && 'Date'[Date] <= maxDate )
    )

 

View solution in original post

4 REPLIES 4
Ashish_Mathur
Super User
Super User

Hi,

To your visual, drag Date from the Date Table.  Try this measure

=IF(MAX('Date'[Date])<=TODAY(),CALCULATE([Total Schedule],DATESBETWEEN('Date'[Date],TODAY(),EOMONTH(TODAY(),0))),[Total Schedule])

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
AlB
Super User
Super User

Hi @Connerf 

I'm not sure I understand completely what you're after. Is it a measure that you want, to be used with dates in the rows of a matrix visual? Do you want [Total schedule] evaluated betweeen today and the end of the current month or up to the date on the current row for future months? If so:

 

TG Production =
VAR maxDate =
    IF (
        MONTH ( TODAY () ) = MONTH ( SELECTEDVALUE('Date'[Date] )),
        EOMONTH ( TODAY (), 0 ),
        SELECTEDVALUE ( 'Date'[Date] )
    )
RETURN
    CALCULATE (
        [Total Schedule],
        FILTER ( 'Date', 'Date'[Date] >= TODAY () && 'Date'[Date] <= maxDate )
    )

@Connerf 

Ok, try this slight change then. Remember to always show an example based on your data to explain what you need. It is very helpful for those trying to provide an answer

TG Production =
VAR maxDate =
    IF (
        MONTH ( TODAY () ) = MONTH ( MAX('Date'[Date] )),
        EOMONTH ( TODAY (), 0 ),
        MAX ( 'Date'[Date] )
    )
RETURN
    CALCULATE (
        [Total Schedule],
        FILTER ( 'Date', 'Date'[Date] >= TODAY () && 'Date'[Date] <= maxDate )
    )

 

Connerf
Frequent Visitor

@AlB,

 

Thanks for your work on this. 

 

I do want the measure to be used in a matrix and column chart. For the current month, it should just show [Total Schedule] from TODAY() until EOM. For months in the future, it should just show [Total Schedule].

 

The code you provided works when I've drilled down to the lowest level ('Date'[Date]), however, how do I get the code to work when I roll up to a week or month?

 

Thanks,

C

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 MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.