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

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.

Reply
jonnyA
Responsive Resident
Responsive Resident

Creating a measure for # of days in a month

I'm trying to figure out how to take my Charges divided by # of days in the month or months selected.

 

I think if someone could tell me how to write a measure that displays the # of days in a month i could figure it out by taking the "Charges" divided by "# of days per month chosen"

 

For example:

If my "charges" were $10,000 in October then I would divide that by "31 days" (The total days in October)  then my answer is $322.58.

2 ACCEPTED SOLUTIONS

Hi @jonnyA ,

Seems like you do not have a calendar table, create a calculated table like this based on your [Month Year Sort]:

Calendar = CALENDAR("2017/9/1","2018/12/31")

Create a calculated column for it which is simliar with the [Month Year Sort]:

mthy =
(
    YEAR ( 'Calendar'[Date] ) * 100
        + MONTH ( 'Calendar'[Date] )
) & " - " & 'Calendar'[Date].[Month]

Create a measure to calculated the result:

Result = 
SUM ( 'MthYear_Sort'[Charges] )
    / CALCULATE (
        COUNT ( 'Calendar'[Date] ),
        FILTER (
            ALL ( 'Calendar' ),
            'Calendar'[mthy] IN DISTINCT ( 'MthYear_Sort'[Month Year Sort] )
        )
    )

re.png

Attached the sample file in the below, hopes to help you.

 

Best Regards,
Community Support Team _ Yingjie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

View solution in original post

Hi @jonnyA ,

Seems like you do not have a calendar table, create a calculated table like this based on your [Month Year Sort]:

Calendar = CALENDAR("2017/9/1","2018/12/31")

Create a calculated column for it which is simliar with the [Month Year Sort]:

mthy =
(
    YEAR ( 'Calendar'[Date] ) * 100
        + MONTH ( 'Calendar'[Date] )
) & " - " & 'Calendar'[Date].[Month]

Create a measure to calculated the result:

Result = 
SUM ( 'MthYear_Sort'[Charges] )
    / CALCULATE (
        COUNT ( 'Calendar'[Date] ),
        FILTER (
            ALL ( 'Calendar' ),
            'Calendar'[mthy] IN DISTINCT ( 'MthYear_Sort'[Month Year Sort] )
        )
    )

re.png

Attached the sample file in the below, hopes to help you.

 

Best Regards,
Community Support Team _ Yingjie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

View solution in original post

8 REPLIES 8
jonnyA
Responsive Resident
Responsive Resident

@v-yingjl I have a MTHYear_Sort with my data, however, i do not know how to write the measure?  Can you help me out writing the measure?  I think I need to plug in MTHYear_Sort somewhere, but I do not know how to do it?  Appreciate the help!!!

 

jonnyA_0-1609378698870.png

 

 

 

Hi @jonnyA ,

What does the [MTHYear_Sort] represent in your table? The date column, the month column or anything else?

Could you please consider sharing a simple sample data without any sesentive information abouth this issue for further discussion which could let us better to help you solve it.

 

Best Regards,
Community Support Team _ Yingjie Li

 

jonnyA
Responsive Resident
Responsive Resident

Here is an example of what the "MthYear_Sort" Table represents ...

 

jonnyA_0-1609421022412.png

Is this what you're looking for?

Hi @jonnyA ,

Seems like you do not have a calendar table, create a calculated table like this based on your [Month Year Sort]:

Calendar = CALENDAR("2017/9/1","2018/12/31")

Create a calculated column for it which is simliar with the [Month Year Sort]:

mthy =
(
    YEAR ( 'Calendar'[Date] ) * 100
        + MONTH ( 'Calendar'[Date] )
) & " - " & 'Calendar'[Date].[Month]

Create a measure to calculated the result:

Result = 
SUM ( 'MthYear_Sort'[Charges] )
    / CALCULATE (
        COUNT ( 'Calendar'[Date] ),
        FILTER (
            ALL ( 'Calendar' ),
            'Calendar'[mthy] IN DISTINCT ( 'MthYear_Sort'[Month Year Sort] )
        )
    )

re.png

Attached the sample file in the below, hopes to help you.

 

Best Regards,
Community Support Team _ Yingjie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Hi @jonnyA ,

Seems like you do not have a calendar table, create a calculated table like this based on your [Month Year Sort]:

Calendar = CALENDAR("2017/9/1","2018/12/31")

Create a calculated column for it which is simliar with the [Month Year Sort]:

mthy =
(
    YEAR ( 'Calendar'[Date] ) * 100
        + MONTH ( 'Calendar'[Date] )
) & " - " & 'Calendar'[Date].[Month]

Create a measure to calculated the result:

Result = 
SUM ( 'MthYear_Sort'[Charges] )
    / CALCULATE (
        COUNT ( 'Calendar'[Date] ),
        FILTER (
            ALL ( 'Calendar' ),
            'Calendar'[mthy] IN DISTINCT ( 'MthYear_Sort'[Month Year Sort] )
        )
    )

re.png

Attached the sample file in the below, hopes to help you.

 

Best Regards,
Community Support Team _ Yingjie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

v-yingjl
Community Support
Community Support

Hi @jonnyA ,

Based on your description, if you do not have a date table, you can create a calendar table like this:

Calendar = CALENDAR("2020/1/1","2020/12/31")

Create a measure like this:

Result = 
CALCULATE (
    SUM ( 'Table'[charges] ) / COUNT ( 'Calendar'[Date] ),
    FILTER (
        'Table',
        'Table'[Month] = SELECTEDVALUE ( 'Calendar'[Date].[MonthNo] )
    )
)

re.png

Attached a sample file in the below, hopes to help you.

 

Best Regards,
Community Support Team _ Yingjie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

edhans
Super User
Super User

@jonnyA ,  @AlB is correct, a Date Table makes this a snap. I have a date table here - https://bit.ly/DateTableByEd - that will give you a pretty comprehensive date table. You can count rows if your dates are filtered properly, or use the [Days in Month] field in this date table.

 

 



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting
AlB
Community Champion
Community Champion

Hi @jonnyA 

Assuming you have a date table ( create one otherwise):

Measure = COUNT( DateTable[Date] )

 

Please mark the question solved when done and consider giving a thumbs up if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

SU18_powerbi_badge

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 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.

Top Kudoed Authors