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
Anonymous
Not applicable

Request: DAX Formula help for previous month calcuation with condition to skip months of Jan and Jul

Hi All,

 

I am trying to create a caluclated column that would show a meeting taking place a month beore each date in the original column, the condition being if the meeting would fall in January or July then the 2nd columns Meeting date should instead reflect is occuring in December or June respecively. it would look like the following:

Excel piwer bi example.png

The general formula sees to be delivering on its function, to recall the month before. However I have noticed some discrepencies in the data - namely the formula is still not skipping January and July month meetings, instead showing meetings to occur then (instead of marking them as December and June month meetings as it should function). Additionally December decision dates are showing October month meetings (instead of November). This is the formula i am using:

 

Meeting Month = 
VAR _sldate =
    CALCULATE ( SELECTEDVALUE ( 'Decisions Register (2)'[Latest Decision Due Date] ) )
VAR _twomonthback =
    EDATE ( _sldate, -2 )
VAR _onemonthback =
    EDATE ( _sldate, -1 )
VAR _p1 =
    EOMONTH ( 'Decisions Register (2)'[Latest Decision Due Date], -1 )
VAR _p2 =
    EOMONTH ( 'Decisions Register (2)'[Latest Decision Due Date], -2 )
VAR _isbalnkprev =
    ISBLANK (
        COUNTROWS (
            FILTER (
                'Decisions Register (2)',
                'Decisions Register (2)'[Latest Decision Due Date] > _p2
                    && 'Decisions Register (2)'[Latest Decision Due Date] <= _p1
            )
        )
    )
VAR _result =
    IF (  _isbalnkprev,_twomonthback,_onemonthback )
RETURN
    _result 

 

 

 

Here is a sample of the table that is generated, note the aforementioned skipping of November skipping of January and July month meetings, instead showing meetings to occur then (instead of marking them as December and June month meetings as it should function). Additionally December decision dates are showing October month meetings (instead of November):

       

Latest Decision Due Date  Meeting Month 
Friday, 22 July 2022May 2022
Monday, 31 August 2020July 2020
Sunday, 31 December 2023October 2023
Friday, 8 May 2020April 2020
Monday, 31 August 2020July 2020
Sunday, 31 December 2023October 2023
Thursday, 30 April 2020March 2020
Friday, 30 October 2020September 2020
Monday, 31 August 2020July 2020
Thursday, 1 October 2020September 2020
Thursday, 1 October 2020September 2020
Friday, 8 May 2020April 2020
Sunday, 1 November 2020October 2020
Thursday, 1 October 2020September 2020
Friday, 1 May 2020April 2020
Thursday, 30 April 2020March 2020
Monday, 31 August 2020July 2020
Sunday, 31 December 2023October 2023
Friday, 31 December 2021October 2021
Monday, 31 August 2020July 2020
Sunday, 31 December 2023October 2023
Thursday, 30 April 2020March 2020
Friday, 30 October 2020September 2020
Friday, 24 July 2020June 2020
Friday, 8 May 2020April 2020
Monday, 31 August 2020July 2020
Friday, 12 June 2020May 2020
Friday, 1 May 2020April 2020
Friday, 22 July 2022May 2022
Tuesday, 31 March 2020February 2020
Friday, 31 December 2021October 2021
Monday, 31 August 2020July 2020
Sunday, 31 December 2023October 2023
Thursday, 30 April 2020March 2020
Friday, 30 October 2020September 2020
Friday, 8 May 2020April 2020
Friday, 8 May 2020April 2020
Friday, 24 July 2020June 2020
Tuesday, 31 December 2019October 2019
Friday, 24 July 2020June 2020
Friday, 31 December 2021October 2021
Sunday, 31 December 2023October 2023
Thursday, 30 April 2020March 2020
Friday, 30 October 2020September 2020
Friday, 12 June 2020May 2020
Tuesday, 1 September 2020August 2020
Friday, 12 June 2020May 2020
Friday, 1 May 2020April 2020
Friday, 1 May 2020April 2020
Monday, 17 January 2022December 2021
Friday, 12 June 2020May 2020
Saturday, 29 February 2020January 2020
Friday, 24 July 2020June 2020
Monday, 17 January 2022December 2021
Sunday, 31 December 2023October 2023
Friday, 30 October 2020September 2020
Friday, 12 June 2020May 2020
Sunday, 31 December 2023October 2023
Thursday, 30 April 2020March 2020
Friday, 30 October 2020September 2020
Thursday, 1 October 2020September 2020
Thursday, 1 October 2020September 2020
Thursday, 30 April 2020March 2020
Thursday, 1 October 2020September 2020
Thursday, 1 October 2020September 2020
Friday, 1 May 2020April 2020
Saturday, 29 February 2020January 2020
Friday, 30 October 2020September 2020
Monday, 31 August 2020July 2020
Friday, 12 June 2020May 2020
Sunday, 31 December 2023October 2023
Thursday, 30 April 2020March 2020
Friday, 30 October 2020September 2020
Monday, 17 January 2022December 2021
Monday, 17 January 2022December 2021
Monday, 17 January 2022December 2021
Friday, 12 June 2020May 2020
Friday, 12 June 2020May 2020
Sunday, 31 December 2023October 2023
Thursday, 30 April 2020March 2020
Friday, 30 October 2020September 2020
Sunday, 1 November 2020October 2020
Friday, 30 October 2020September 2020
Friday, 30 October 2020September 2020
Friday, 12 June 2020May 2020
Friday, 8 May 2020April 2020
Sunday, 31 December 2023October 2023
Sunday, 31 December 2023October 2023
Friday, 12 June 2020May 2020
Sunday, 31 December 2023October 2023
Thursday, 30 April 2020March 2020
Friday, 30 October 2020September 2020
Friday, 8 May 2020April 2020
Monday, 31 August 2020July 2020
Monday, 31 August 2020July 2020
Sunday, 31 December 2023October 2023
Thursday, 30 April 2020March 2020
Friday, 30 October 2020September 2020
Thursday, 14 September 2023July 2023
Friday, 30 October 2020September 2020
Friday, 30 October 2020September 2020
Thursday, 30 April 2020March 2020
Friday, 12 June 2020May 2020
Sunday, 31 December 2023October 2023
Thursday, 30 April 2020March 2020
Friday, 30 October 2020September 2020
Friday, 30 October 2020September 2020
Friday, 12 June 2020May 2020
Friday, 24 July 2020June 2020
Saturday, 1 July 2023June 2023
Saturday, 29 February 2020January 2020
Friday, 31 December 2021October 2021
Friday, 31 December 2021October 2021
Sunday, 31 December 2023October 2023
Thursday, 30 April 2020March 2020
Friday, 30 October 2020September 2020
Friday, 24 July 2020June 2020

 

 

I have tried creating tinkering with the formula but it has not worked. I would appreciate any assistance as I am a beginner.

Thank you for your time!!
Ankit

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Here's the column:

Meeting Month = 
    var __currentDate = 'Dates'[Latest Decision Due Date]
    var __currentYear = YEAR( __currentDate )
    var __currentDateMonth = MONTH( __currentDate )
    var __oneMonthBefore = MOD( __currentDateMonth - 2, 12 ) + 1
    var __adjustedOneMonthBefore =
        IF( __oneMonthBefore in {1,7},
            MOD( __oneMonthBefore - 2, 12 ) + 1,
            __oneMonthBefore
        )
    return
        if( __adjustedOneMonthBefore = 12,
            date( __currentYear - 1, __adjustedOneMonthBefore, 1),
            date( __currentYear, __adjustedOneMonthBefore, 1)
        )

 

MOD returns the remainder (modulo) of the integer division of a and b. If you want to move back one month, you have to move from 1 to 12 and this formula does it: MOD( 1 - 2, 12 ) + 1 = 11 + 1 = 12. MOD( m - 2, 12 ) + 1 = m - 1 for  1 < m <= 12.

 

Best

D

View solution in original post

1 REPLY 1
Anonymous
Not applicable

Here's the column:

Meeting Month = 
    var __currentDate = 'Dates'[Latest Decision Due Date]
    var __currentYear = YEAR( __currentDate )
    var __currentDateMonth = MONTH( __currentDate )
    var __oneMonthBefore = MOD( __currentDateMonth - 2, 12 ) + 1
    var __adjustedOneMonthBefore =
        IF( __oneMonthBefore in {1,7},
            MOD( __oneMonthBefore - 2, 12 ) + 1,
            __oneMonthBefore
        )
    return
        if( __adjustedOneMonthBefore = 12,
            date( __currentYear - 1, __adjustedOneMonthBefore, 1),
            date( __currentYear, __adjustedOneMonthBefore, 1)
        )

 

MOD returns the remainder (modulo) of the integer division of a and b. If you want to move back one month, you have to move from 1 to 12 and this formula does it: MOD( 1 - 2, 12 ) + 1 = 11 + 1 = 12. MOD( m - 2, 12 ) + 1 = m - 1 for  1 < m <= 12.

 

Best

D

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.