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
KA95
Helper III
Helper III

Get value for current month

Hi there,

I have a matrix table with numerous different values for different timescales, I wanted to know how to get a value for the current month? It's more complex than I thought. 

I have a simple measure called [User Count] which is what I need counting over the time period, then I have a date table built around [active_date] as shown below:

Dates = ADDCOLUMNS ( CALENDAR (FIRSTDATE('Candidate Activity'[active_date]), TODAY()), "year", YEAR ( [Date] ), "MonthNumber", FORMAT ( [Date], "MM" ), "year-month", FORMAT ( [Date], "YYYY-MM" ), "month-year", FORMAT ( [Date], "MM-'YY" ) )
 
Do you know how I can build a simple measure that will calculate [User Count] for the current month of [active_date] ? 
4 REPLIES 4
v-chenwuz-msft
Community Support
Community Support

Hi @KA95 ,

 

Please use the column from the date table "Dates" as the fields of table visual?

And measure like the following expression:

Measure =
CALCULATE (
    [User Count],
    FILTER (
        ALLSELECTED ( 'Candidate Activity' ),
        YEAR ( 'Candidate Activity'[active_date] ) = SELECTEDVALUE ( Dates[year] )
            && MONTH ( 'Candidate Activity'[active_date] )
                = SELECTEDVALUE ( Date[MonthNumber] )
    )
)

 

Or you can share some example data and expect result if you need more help.

 

Best Regards

Community Support Team _ chenwu zhu

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi @v-chenwuz-msft 

Thank you for the response, the measure had no errors itself, but when I put it into a visual it has an error, and this is the error:

Error Message:
MdxScript(Model) (40, 16) Calculation error in measure 'Candidate Activity'[In last Month]: DAX comparison operations do not support comparing values of type Integer with values of type Text. Consider using the VALUE or FORMAT function to convert one of the values.

I'm not sure why this is? I shouldn't convert the [active_date] should I? 

Hi @KA95 ,

 

Please change the type of the two columns in your table which you have mentioned in this measure.

Or use the VALUE or FORMAT function to convert one of the values.

 

If you need more help, please share your pbix file without sensitive data.

Best Regards

Community Support Team _ chenwu zhu

Hi @v-chenwuz-msft 

I've changed the [MonthNumber] column in dates table to a whole number, but now the data is just blank, here is what it looks like when I put it on my visual below: 

KA95_0-1655367973457.png

This is what the date table looks like below:

KA95_1-1655368042221.png

I did notice that when I converted the MonthNumber into a wholenumber it went from 01 to 1, 02 to 2, etc. Could this be the problem maybe? Or does that not matter? 

 

 

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.

Top Solution Authors