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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
Ainala
Frequent Visitor

Need Help with Current Month, Total year DAX

Hello Power Users,

 

I'm struggling with some dax measures. I have 2 slicers from Date table ( Year and Month). I would like to create measures for Month(First Day of the month-Last Day of the month), YeartoCurrentMonth( First Day of the year - Last day of the month) and TotalYear(First Day of the year - Last day of the Year). 

 

If the user selects Year-2022 and Month-June or 6 in the slicers then i need to calculate Openorders.

 

Current Month Orders6/1/22 - 6/30/22
Current Year upto current month Orders1/1/22 - 6/30/22
Whole Current year Orders1/1/22 - 12/31/22

 

Please help me with the calculation.

 

Thanks,

 

1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi,

Please check the attached pbix file below.

I tried to create a sample pbix file, and the data model looks like the below.

All measures are in the attached pbix file.

 

Untitled.png

 

Current month orders: = 
VAR _currentyear =
    MAX ( 'Calendar'[Year] )
VAR _currentmonth =
    MAX ( 'Calendar'[Month] )
VAR _lastdateofthemonth =
    CALCULATE (
        MAX ( 'Calendar'[Date] ),
        FILTER (
            ALL ( 'Calendar' ),
            'Calendar'[Year] = _currentyear
                && 'Calendar'[Month] = _currentmonth
        )
    )
VAR _periodtable =
    FILTER (
        ALL ( 'Calendar' ),
        'Calendar'[Date] <= _lastdateofthemonth
            && 'Calendar'[Year] = _currentyear
            && 'Calendar'[Month] = _currentmonth
    )
RETURN
    CALCULATE ( SUM ( Data[Order] ), _periodtable )

 

Current year  upto current month orders: = 
VAR _currentyear =
    MAX ( 'Calendar'[Year] )
VAR _currentmonth =
    MAX ( 'Calendar'[Month] )
VAR _lastdateofthemonth =
    CALCULATE (
        MAX ( 'Calendar'[Date] ),
        FILTER (
            ALL ( 'Calendar' ),
            'Calendar'[Year] = _currentyear
                && 'Calendar'[Month] = _currentmonth
        )
    )
VAR _periodtable =
    FILTER (
        ALL ( 'Calendar' ),
        'Calendar'[Date] <= _lastdateofthemonth
            && 'Calendar'[Year] = _currentyear
    )
RETURN
    CALCULATE ( SUM ( Data[Order] ), _periodtable )

 

Current year all orders: = 
VAR _currentyear =
    MAX ( 'Calendar'[Year] )
VAR _lastdateoftheyear =
    CALCULATE (
        MAX ( 'Calendar'[Date] ),
        FILTER (
            ALL ( 'Calendar' ),
            'Calendar'[Year] = _currentyear
        )
    )
VAR _periodtable =
    FILTER (
        ALL ( 'Calendar' ),
        'Calendar'[Date] <= _lastdateoftheyear
            && 'Calendar'[Year] = _currentyear
    )
RETURN
    CALCULATE ( SUM ( Data[Order] ), _periodtable )

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.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

View solution in original post

2 REPLIES 2
Ainala
Frequent Visitor

@Jihwan_Kim Thank you so much, It worked like a champ

Jihwan_Kim
Super User
Super User

Hi,

Please check the attached pbix file below.

I tried to create a sample pbix file, and the data model looks like the below.

All measures are in the attached pbix file.

 

Untitled.png

 

Current month orders: = 
VAR _currentyear =
    MAX ( 'Calendar'[Year] )
VAR _currentmonth =
    MAX ( 'Calendar'[Month] )
VAR _lastdateofthemonth =
    CALCULATE (
        MAX ( 'Calendar'[Date] ),
        FILTER (
            ALL ( 'Calendar' ),
            'Calendar'[Year] = _currentyear
                && 'Calendar'[Month] = _currentmonth
        )
    )
VAR _periodtable =
    FILTER (
        ALL ( 'Calendar' ),
        'Calendar'[Date] <= _lastdateofthemonth
            && 'Calendar'[Year] = _currentyear
            && 'Calendar'[Month] = _currentmonth
    )
RETURN
    CALCULATE ( SUM ( Data[Order] ), _periodtable )

 

Current year  upto current month orders: = 
VAR _currentyear =
    MAX ( 'Calendar'[Year] )
VAR _currentmonth =
    MAX ( 'Calendar'[Month] )
VAR _lastdateofthemonth =
    CALCULATE (
        MAX ( 'Calendar'[Date] ),
        FILTER (
            ALL ( 'Calendar' ),
            'Calendar'[Year] = _currentyear
                && 'Calendar'[Month] = _currentmonth
        )
    )
VAR _periodtable =
    FILTER (
        ALL ( 'Calendar' ),
        'Calendar'[Date] <= _lastdateofthemonth
            && 'Calendar'[Year] = _currentyear
    )
RETURN
    CALCULATE ( SUM ( Data[Order] ), _periodtable )

 

Current year all orders: = 
VAR _currentyear =
    MAX ( 'Calendar'[Year] )
VAR _lastdateoftheyear =
    CALCULATE (
        MAX ( 'Calendar'[Date] ),
        FILTER (
            ALL ( 'Calendar' ),
            'Calendar'[Year] = _currentyear
        )
    )
VAR _periodtable =
    FILTER (
        ALL ( 'Calendar' ),
        'Calendar'[Date] <= _lastdateoftheyear
            && 'Calendar'[Year] = _currentyear
    )
RETURN
    CALCULATE ( SUM ( Data[Order] ), _periodtable )

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.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors