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
mwasekaar
Regular Visitor

DAX for % change of Previous and Prioor Privious Month

I Had to show Top 1 category in my KPI card with respect to sales .Which I shown using TopN function. Now I want to show % change for this category for Previous and Prior Previous Month such that current month shall be excluded . meaning in my dataset which is a monthly sales having 12 Month Data from 1 Jan 2024 to 10 Dec 2024 then Dec month should exclude which doing % calculation . I stucked in writing DAX please help me 

1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi,

I am not sure how your semantic model looks like, but I tried to create a sample pbix file like below.

Please check the below picture and the attached pbix file.

I tried using INDEX DAX function.

 

INDEX function (DAX) - DAX | Microsoft Learn

 

 

Jihwan_Kim_1-1742184390855.png

 

 

Jihwan_Kim_0-1742184328671.png

 

Sales: = 
SUM(sales[sales])

 

latest year-month sales: = 
VAR _saleslatestdate =
    MAXX (
        CALCULATETABLE (
            SUMMARIZE ( sales, 'calendar'[Date] ),
            REMOVEFILTERS ( 'calendar' )
        ),
        'calendar'[Date]
    )
VAR _endofmonth =
    EOMONTH ( _saleslatestdate, 0 )
VAR _yearmonth =
    FILTER (
        ALL ( 'calendar'[Year-Month], 'calendar'[Year-Month sort] ),
        'calendar'[Year-Month sort] <= _endofmonth
    )
VAR _t =
    INDEX ( 1, _yearmonth, ORDERBY ( 'calendar'[Year-Month sort], DESC ) )
RETURN
    CALCULATE ( [Sales:], _t )

 

 

previous year-month sales: = 
VAR _saleslatestdate =
    MAXX (
        CALCULATETABLE (
            SUMMARIZE ( sales, 'calendar'[Date] ),
            REMOVEFILTERS ( 'calendar' )
        ),
        'calendar'[Date]
    )
VAR _endofmonth =
    EOMONTH ( _saleslatestdate, 0 )
VAR _yearmonth =
    FILTER (
        ALL ( 'calendar'[Year-Month], 'calendar'[Year-Month sort] ),
        'calendar'[Year-Month sort] <= _endofmonth
    )
VAR _t =
    INDEX ( 2, _yearmonth, ORDERBY ( 'calendar'[Year-Month sort], DESC ) )
RETURN
    CALCULATE ( [Sales:], _t )

 

prior previous year-month sales: = 
VAR _saleslatestdate =
    MAXX (
        CALCULATETABLE (
            SUMMARIZE ( sales, 'calendar'[Date] ),
            REMOVEFILTERS ( 'calendar' )
        ),
        'calendar'[Date]
    )
VAR _endofmonth =
    EOMONTH ( _saleslatestdate, 0 )
VAR _yearmonth =
    FILTER (
        ALL ( 'calendar'[Year-Month], 'calendar'[Year-Month sort] ),
        'calendar'[Year-Month sort] <= _endofmonth
    )
VAR _t =
    INDEX ( 3, _yearmonth, ORDERBY ( 'calendar'[Year-Month sort], DESC ) )
RETURN
    CALCULATE ( [Sales:], _t )

 

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.


Visit my LinkedIn page by clicking here.


Schedule a meeting with me to discuss further by clicking here.

View solution in original post

2 REPLIES 2
Jihwan_Kim
Super User
Super User

Hi,

I am not sure how your semantic model looks like, but I tried to create a sample pbix file like below.

Please check the below picture and the attached pbix file.

I tried using INDEX DAX function.

 

INDEX function (DAX) - DAX | Microsoft Learn

 

 

Jihwan_Kim_1-1742184390855.png

 

 

Jihwan_Kim_0-1742184328671.png

 

Sales: = 
SUM(sales[sales])

 

latest year-month sales: = 
VAR _saleslatestdate =
    MAXX (
        CALCULATETABLE (
            SUMMARIZE ( sales, 'calendar'[Date] ),
            REMOVEFILTERS ( 'calendar' )
        ),
        'calendar'[Date]
    )
VAR _endofmonth =
    EOMONTH ( _saleslatestdate, 0 )
VAR _yearmonth =
    FILTER (
        ALL ( 'calendar'[Year-Month], 'calendar'[Year-Month sort] ),
        'calendar'[Year-Month sort] <= _endofmonth
    )
VAR _t =
    INDEX ( 1, _yearmonth, ORDERBY ( 'calendar'[Year-Month sort], DESC ) )
RETURN
    CALCULATE ( [Sales:], _t )

 

 

previous year-month sales: = 
VAR _saleslatestdate =
    MAXX (
        CALCULATETABLE (
            SUMMARIZE ( sales, 'calendar'[Date] ),
            REMOVEFILTERS ( 'calendar' )
        ),
        'calendar'[Date]
    )
VAR _endofmonth =
    EOMONTH ( _saleslatestdate, 0 )
VAR _yearmonth =
    FILTER (
        ALL ( 'calendar'[Year-Month], 'calendar'[Year-Month sort] ),
        'calendar'[Year-Month sort] <= _endofmonth
    )
VAR _t =
    INDEX ( 2, _yearmonth, ORDERBY ( 'calendar'[Year-Month sort], DESC ) )
RETURN
    CALCULATE ( [Sales:], _t )

 

prior previous year-month sales: = 
VAR _saleslatestdate =
    MAXX (
        CALCULATETABLE (
            SUMMARIZE ( sales, 'calendar'[Date] ),
            REMOVEFILTERS ( 'calendar' )
        ),
        'calendar'[Date]
    )
VAR _endofmonth =
    EOMONTH ( _saleslatestdate, 0 )
VAR _yearmonth =
    FILTER (
        ALL ( 'calendar'[Year-Month], 'calendar'[Year-Month sort] ),
        'calendar'[Year-Month sort] <= _endofmonth
    )
VAR _t =
    INDEX ( 3, _yearmonth, ORDERBY ( 'calendar'[Year-Month sort], DESC ) )
RETURN
    CALCULATE ( [Sales:], _t )

 

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.


Visit my LinkedIn page by clicking here.


Schedule a meeting with me to discuss further by clicking here.

techies
Solution Supplier
Solution Supplier

Hi @mwasekaar can you please share the DAX you are using for top category? just want to align further

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