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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
yogi678_1
Regular Visitor

Result Not DIsplay Uisng NextMonth Function

Hi, I have a dataset with date type column called Contract End Date. I have created a new column called Extracted_Contract_End_Date to extract the date in MMM-YYYY format.  Then I have created a measure from the Contract End Date using NextMonth function hoping to get the total count for next month contract that will expire.
test.png

However, the measure is not able to display the result in the matrix table.

yogi678_1_0-1714030569916.png

The DAX code for the measure is as below:

Contract_Expire_Next_Month = CALCULATE(COUNT(Sheet1[Contract End Date]), NEXTMONTH(Sheet1[Contract End Date]))

Can anyone advise me please? Thank you.

 

2 ACCEPTED SOLUTIONS

If I understand correctly, you need the count of expiring contracts next month for each record in your table, right?
NEXTMONTH() will get you a column of all dates in the following month.
Maybe something like this would help:

 

Expiring Contracts Next Month = 
VAR CurrentDate = MAX(Tabelle[End Date])  // To get the date in context
VAR FirstDayNextMonth = EOMONTH(CurrentDate, 0) + 1
VAR LastDayNextMonth = EOMONTH(CurrentDate, 1)
VAR ContractCount = CALCULATE(
    COUNTROWS(Tabelle),
    ALL(Tabelle[EndMonth]),  // Remove the filter context imposed by EndMonth, else the measure would not work, when you add EndMonth.
    Tabelle[End Date] >= FirstDayNextMonth,
    Tabelle[End Date] <= LastDayNextMonth
)
RETURN
IF(ISBLANK(ContractCount), 0, ContractCount)

 

aschkan_0-1714056372811.png

View solution in original post

Hi @aschkan 

 

You are on the right track. It worked like a charm!

 

Depending on @alvin1999 needs, the approach can be modified like this:

 

Expiring Contracts Next Month = 
VAR CurrentDate = MAX('Table'[Extracted_Contract End Date])  // To get the date in context
VAR FirstDayNextMonth = EOMONTH(CurrentDate, 0) + 1
VAR LastDayNextMonth = EOMONTH(CurrentDate, 1)
VAR ContractCount = CALCULATE(
    COUNTROWS('Table'),
    ALL('Table'),  // Remove the filter context imposed by EndMonth, else the measure would not work, when you add EndMonth.
    'Table'[Extracted_Contract End Date] >= FirstDayNextMonth,
    'Table'[Extracted_Contract End Date] <= LastDayNextMonth
)
RETURN
IF(ISBLANK(ContractCount), 0, ContractCount)

 

vxuxinyimsft_0-1714113303812.png

Notes: By the way I am following the steps below to set the Extracted_Contract End Date because after my testing it may cause an error if I use the FORMAT function.

vxuxinyimsft_3-1714114006316.png

 

if I use the FORMAT function

vxuxinyimsft_5-1714114265387.png

 

Best Regards,
Yulia Xu

View solution in original post

4 REPLIES 4
yogi678_1
Regular Visitor

My expected result in the matrix table is like the screenshot below:

yogi678_1_0-1714031436862.png

 

If I understand correctly, you need the count of expiring contracts next month for each record in your table, right?
NEXTMONTH() will get you a column of all dates in the following month.
Maybe something like this would help:

 

Expiring Contracts Next Month = 
VAR CurrentDate = MAX(Tabelle[End Date])  // To get the date in context
VAR FirstDayNextMonth = EOMONTH(CurrentDate, 0) + 1
VAR LastDayNextMonth = EOMONTH(CurrentDate, 1)
VAR ContractCount = CALCULATE(
    COUNTROWS(Tabelle),
    ALL(Tabelle[EndMonth]),  // Remove the filter context imposed by EndMonth, else the measure would not work, when you add EndMonth.
    Tabelle[End Date] >= FirstDayNextMonth,
    Tabelle[End Date] <= LastDayNextMonth
)
RETURN
IF(ISBLANK(ContractCount), 0, ContractCount)

 

aschkan_0-1714056372811.png

Hi @aschkan 

 

You are on the right track. It worked like a charm!

 

Depending on @alvin1999 needs, the approach can be modified like this:

 

Expiring Contracts Next Month = 
VAR CurrentDate = MAX('Table'[Extracted_Contract End Date])  // To get the date in context
VAR FirstDayNextMonth = EOMONTH(CurrentDate, 0) + 1
VAR LastDayNextMonth = EOMONTH(CurrentDate, 1)
VAR ContractCount = CALCULATE(
    COUNTROWS('Table'),
    ALL('Table'),  // Remove the filter context imposed by EndMonth, else the measure would not work, when you add EndMonth.
    'Table'[Extracted_Contract End Date] >= FirstDayNextMonth,
    'Table'[Extracted_Contract End Date] <= LastDayNextMonth
)
RETURN
IF(ISBLANK(ContractCount), 0, ContractCount)

 

vxuxinyimsft_0-1714113303812.png

Notes: By the way I am following the steps below to set the Extracted_Contract End Date because after my testing it may cause an error if I use the FORMAT function.

vxuxinyimsft_3-1714114006316.png

 

if I use the FORMAT function

vxuxinyimsft_5-1714114265387.png

 

Best Regards,
Yulia Xu

When we remove the End Date column in the matrix table, the measure will not work. 
Can I know how to troubleshoot it?

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.