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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.

Reply
RobinNeven
Helper I
Helper I

Use first of next month in the CALCULATE filter of a measure within a certain filter context

Dear Power BI community,

 

I have the following measure 'SumMonth1', which works fine (see below). Now I want the same measure, but instead of having the filter on MIN('Contract peildatum'[Contract peildatum]) I want that to be the first of next month (whatever that next month is within the current filter context).

 

SumMonth1 = 
    CALCULATE (
        DISTINCTCOUNT( Contracthistorie[ContractId] ),
        ALLEXCEPT (
            Contracthistorie,
            'Contract peildatum'[Contract peildatum],
            'Contract peildatum'[Contract peiljaarmaand],
            'Contract peildatum'[Is start contract peilweek],
            'Klantlabel'[Klantlabel groepcode],
            'Klantlabel'[Klantlabel code],
            'Product'[Product groepcode]
        ),
        'Contract peildatum'[Contract peildatum] = MIN('Contract peildatum'[Contract peildatum])
    )

 

The goal is to get the difference between the two totals in below picture (blanked out), whatever the selection is in the slicer (assuming always two selections):

 

MonthByMonthComparison.png

 

So the left total I solved, that's what measure 'SumMonth1' is for. Now I just need to know how to dynamically calculate the total on the right, so that I can subtract the two.

 

The following for the total on the right (SumMonth2) doesn't work by the way, because the MAX('Contract peildatum'[Contract peildatum]) is 9/30/2021 and not 9/1/2021:

 

SumMonth2 = 
    CALCULATE (
        DISTINCTCOUNT( Contracthistorie[ContractId] ),
        ALLEXCEPT (
            Contracthistorie,
            'Contract peildatum'[Contract peildatum],
            'Contract peildatum'[Contract peiljaarmaand],
            'Contract peildatum'[Is start contract peilweek],
            'Klantlabel'[Klantlabel groepcode],
            'Klantlabel'[Klantlabel code],
            'Product'[Product groepcode]
        ),
        'Contract peildatum'[Contract peildatum] = MAX('Contract peildatum'[Contract peildatum])
    )

 

A lot of DAX statements do not work in the filter of a CALCULATE measure I found, like DATEADD, which makes it quite hard. I think it's a matter of just knowing the right DAX statement, but I cannot figure it out. Thanks a lot in advance for any help!

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@RobinNeven , if you want first date on next month

 

SumMonth1 = 
    CALCULATE (
        DISTINCTCOUNT( Contracthistorie[ContractId] ),
        ALLEXCEPT (
            Contracthistorie,
            'Contract peildatum'[Contract peildatum],
            'Contract peildatum'[Contract peiljaarmaand],
            'Contract peildatum'[Is start contract peilweek],
            'Klantlabel'[Klantlabel groepcode],
            'Klantlabel'[Klantlabel code],
            'Product'[Product groepcode]
        ),
        'Contract peildatum'[Contract peildatum] = eomonth(MIN('Contract peildatum'[Contract peildatum]),0)+1
    )

 

 

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

2 REPLIES 2
amitchandak
Super User
Super User

@RobinNeven , if you want first date on next month

 

SumMonth1 = 
    CALCULATE (
        DISTINCTCOUNT( Contracthistorie[ContractId] ),
        ALLEXCEPT (
            Contracthistorie,
            'Contract peildatum'[Contract peildatum],
            'Contract peildatum'[Contract peiljaarmaand],
            'Contract peildatum'[Is start contract peilweek],
            'Klantlabel'[Klantlabel groepcode],
            'Klantlabel'[Klantlabel code],
            'Product'[Product groepcode]
        ),
        'Contract peildatum'[Contract peildatum] = eomonth(MIN('Contract peildatum'[Contract peildatum]),0)+1
    )

 

 

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Of course, adding a day to the last day of the current month works fine for this, silly I didn't think of it. But thanks! 🙂

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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