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
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
    )

 

 

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
    )

 

 

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
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.