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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
kumsha1
Post Patron
Post Patron

DAX to get Monthly totals based on specific filters

Can someone help to check what's wrong with below DAX, it's stopped working recently where VAR SA is not returning any values now....

Our requirement is to get the monthly totals for the selected month, year and attribute, would greatly help if there's any other easy way to do this..TIA

 

 

MTDPlanValue (Monthly) =
VAR SM =
MONTH ( SELECTEDVALUE ( 'CALENDAR'[CALENDAR_DATE] ) )
VAR SY =
YEAR ( SELECTEDVALUE ( 'CALENDAR'[CALENDAR_DATE] ) )
VAR SA =
SELECTEDVALUE ( 'AttributeInfo'[Attribute] )
RETURN
CALCULATE (
SUM( 'Stg_PPD DailyReporting_Live_V'[DAILY_PLAN_VALUE] ),
FILTER (
ALL ( 'CALENDAR' ),
'CALENDAR'[CALENDAR_MONTH] = SM
&& 'CALENDAR'[CALENDAR_YEAR] = SY
),
FILTER (
ALL ( 'AttributeInfo' ),
'AttributeInfo'[Attribute] = SA
)
)

6 REPLIES 6
Jihwan_Kim
Super User
Super User

Hi,

I am not sure how your datamodel looks like, but I assume there are some cases end users select more than two attributes.

If end users keep selecting only one year and only one month, but selecting more than two attributes, and if this is considered as a correct behavior, please try the below.

 

MTDPlanValue (Monthly) =
VAR SM =
    MONTH ( SELECTEDVALUE ( 'CALENDAR'[CALENDAR_DATE] ) )
VAR SY =
    YEAR ( SELECTEDVALUE ( 'CALENDAR'[CALENDAR_DATE] ) )
VAR SA =
    VALUES ( 'AttributeInfo'[Attribute] )
RETURN
    CALCULATE (
        SUM ( 'Stg_PPD DailyReporting_Live_V'[DAILY_PLAN_VALUE] ),
        FILTER (
            ALL ( 'CALENDAR' ),
            'CALENDAR'[CALENDAR_MONTH] = SM
                && 'CALENDAR'[CALENDAR_YEAR] = SY
        ),
        FILTER ( ALL ( 'AttributeInfo' ), 'AttributeInfo'[Attribute] IN SA )
    )

 


 

    Microsoft MVP
 

 

   


      If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


   


     
        LinkedInVisit my LinkedIn page
     

   


   


     
        Outlook BookingSchedule a short Teams meeting to discuss your question

     

   


 


@Jihwan_Kim , users will select one year/month and attribute only...i have tried below simple DAX and it's not returning any value, what could be wrong here, any ideas.. TIA

 

MTDPlanValue (Monthly) =
VAR SA =
    SELECTEDVALUE ( 'AttributeInfo'[Attribute] )
RETURN
    SA

Hi,

It is difficult for me to tell what is going on without seeing your pbix file.

Please try the below measure whether it is returning one value or not. 

 

Checking: =
VAR SA =
    VALUES ( 'AttributeInfo'[Attribute] )
RETURN
    CONCATENATEX ( SA, 'AttributeInfo'[Attribute], ", " )

 


 

    Microsoft MVP
 

 

   


      If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


   


     
        LinkedInVisit my LinkedIn page
     

   


   


     
        Outlook BookingSchedule a short Teams meeting to discuss your question

     

   


 


Ashish_Mathur
Super User
Super User

Hi,

If your Year and Month slicer are from the Calendar table, then this simple measure should work

=SUM( 'Stg_PPD DailyReporting_Live_V'[DAILY_PLAN_VALUE] )

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

@Ashish_Mathur , this measure should always give the Monthly total (for selected month, year and attribute) not the day total.

 

kumsha1_0-1681183865340.png

 

I am still very confused about what you want.  Try this measure

Measure = calculate(SUM( 'Stg_PPD DailyReporting_Live_V'[DAILY_PLAN_VALUE] ),datesbetween(calendar[date],eomoth(min(calendar[date]),-1)+1,eomoth(min(calendar[date]),0))


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Helpful resources

Announcements
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

May 2025 Monthly Update

Fabric Community Update - May 2025

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