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

Microsoft is giving away 50,000 FREE Microsoft Certification exam vouchers. Get Fabric certified for FREE! Learn more

Reply
Mburman-07
Advocate I
Advocate I

How to calculate a measure that uses days in month but for a year

Hi All,

 

I have the below measure that multiplies by number of days in Month.

TNUoS_Measure = (SUM('F_BATTERY_NON_TRADER_REVENUES'[TNUoS charges per SP])*48)*SELECTEDVALUE(DateTime_Calendar[Days in Month])

However, when I want to look at multiple months worth, or for a whole year. The measure returns blank. Screenshot below. My question is how would I calculate this measure but for more than one month/for a year.

Multiple months
Mburman07_0-1731679039031.png

Single Month 

Mburman07_1-1731679081469.png

 





1 ACCEPTED SOLUTION
johnt75
Super User
Super User

I think you can use

TNUoS_Measure =
SUMX (
    VALUES ( DateTime_Calendar[Year Month] ),
    CALCULATE (
        SUM ( 'F_BATTERY_NON_TRADER_REVENUES'[TNUoS charges per SP] ) * 48
            * SELECTEDVALUE ( DateTime_Calendar[Days in Month] )
    )
)

View solution in original post

6 REPLIES 6
v-xianjtan-msft
Community Support
Community Support

Hi @Mburman-07 

 

First of all, thanks to johnt75, ajohnso2 and Bibiano_Geraldo for their great replies to this question.

 

May I ask if their replies has helped you solve your problem? If so, please consider accepting the reply that helped you as a solution, which will benefit users experiencing similar problems.

If you have any other questions, please feel free to contact me.

 

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

Bibiano_Geraldo
Super User
Super User

Hi @Mburman-07 ,

The issue arises because SELECTEDVALUE() returns a value only if a single value is selected in the column. When you select multiple months or a year, the context no longer contains a single value for DateTime_Calendar[Days in Month], causing SELECTEDVALUE() to return BLANK().

To handle this, you can use the bellow DAX:

TNUoS_Measure = 
SUM('F_BATTERY_NON_TRADER_REVENUES'[TNUoS charges per SP]) * 48 * 
SUMX(
    VALUES(DateTime_Calendar[MonthYear]),
    MAX(DateTime_Calendar[Days in Month])
)



If you need a sum of the total days across all selected months (e.g., for overlapping or partial months you can use bellow DAX:

TNUoS_Measure = 
SUM('F_BATTERY_NON_TRADER_REVENUES'[TNUoS charges per SP]) * 48 * 
SUM(DateTime_Calendar[Days in Month])

 

I hope this help you, if yes please give a Kudo and accept as solution.

 

Thank you

ajohnso2
Super User
Super User

First i created a measure to count the number of selected (month slicer) days in each month.

 

Days in Month =
COUNTX(VALUES('Calendar'[Date]),'Calendar'[Date])
 
If you already have this then great.
 
For the multiplier column i used the below DAX
BasexNumDays =
[Amount] * [Days in Month]

Days.gif

johnt75
Super User
Super User

I think you can use

TNUoS_Measure =
SUMX (
    VALUES ( DateTime_Calendar[Year Month] ),
    CALCULATE (
        SUM ( 'F_BATTERY_NON_TRADER_REVENUES'[TNUoS charges per SP] ) * 48
            * SELECTEDVALUE ( DateTime_Calendar[Days in Month] )
    )
)

Hi @johnt75,

Thank you for this, where you have 

VALUES ( DateTime_Calendar[Year Month] )

Are you expecting a value of say October 2024 for example?

Yes, precisely. I usually have a column in the date table which is the start of the month as a date, formatted to display as e.g. "Oct 2024". Very useful in slicers and visuals when you don't want to report down to the day level.

Helpful resources

Announcements
PBIApril_Carousel

Power BI Monthly Update - April 2025

Check out the April 2025 Power BI update to learn about new features.

Notebook Gallery Carousel1

NEW! Community Notebooks Gallery

Explore and share Fabric Notebooks to boost Power BI insights in the new community notebooks gallery.

April2025 Carousel

Fabric Community Update - April 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors