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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Anonymous
Not applicable

Help with Measure Calculation

I am trying to calculate a % change between YTD data and previous month data. that isa calculation that is the percentage change between all my data to date and all my data until previous month.

 

I have calculate my total as such: Sum of dealers selling 8 or more product groups = SUM('18 V'[Dealers Selling 8 or more product Groups])

 

and I just wish to (minus) one month worth of data from that total, in order to then calculate the % change between those two.

 

3 REPLIES 3
daxer-almighty
Solution Sage
Solution Sage

Here's the correct solution, I believe. But I have not yet checked this on a real model. I've just written it...

// Assumptions:
// 1. There's a proper Dates table in the model (marked as a Date table in the model).
// 2. The main fact table is called FactTable.
// 3. Dates[Date] 1:* FactTable[Date]
// 4. In the Dates table there's a column that numbers years. Lets'
//    call it YearNumber (e.g., 2020, 2021...). It should be an integer
//    and will most likely be hidden. What will be exposed as the
//    year will be a string column like with entries like "CY 2020",
//    "CY 2021"...

[YTD MoM %] =
// Dates[Date] is of the datetime datatype without
// the time component. It's the primary key in 
// the Dates table.
var vLastDayWithData =
    CALCULATE(
        MAX( FactTable[Date] ),
        REMOVEFILTERS( )
    )
var vMaxVisibleYear = MAX( Dates[YearNumber] )
var vYtdPeriod =
    // This logic is needed in order to get
    // correct comparisons for periods that
    // have not yet finished. For instance,
    // if you've got data going up to 20 Mar 2020,
    // then you want to compare Mar YTD against
    // Feb YTD but the calculation must go to
    // 20 Feb 2020, not 28 Feb 2020 since that
    // would distort the calculation because
    // Mar 2020 has not yet finished. This logic
    // accounts for this case.
    CALCULATETABLE(
        DATESYTD(
            Dates[Date]
        ),
        KEEPFILTERS(
            Dates[Date] <= vLastDayWithData 
        )
    )
var vYtdPeriodLastMonth =
    CALCULATETABLE(
        DISTINCT( Dates[Date] ),
        DATEADD( vYtdPeriod, -1, MONTH ),
        Dates[YearNumber] = vMaxVisibleYear
     )
var vYtdValue =
    CALCULATE(
        [Measure],
        vYtdPeriod
    )
var vYtdValueLastMonth =
    CALCULATE(
        [Measure],
        vYtdPeriodLastMonth
    )
var vChange =
    DIVIDE(
        vYtdValue - vYtdValueLastMonth,
        vYtdValueLastMonth
    )
return
    vChange

 

daxer-almighty
Solution Sage
Solution Sage

 

[Edit] Sorry, this does something different... but I'll post the right solution in a moment. But try to understand this logic as well as it can be useful 🙂

// Assumptions:
// 1. There's a proper Dates table in the model (marked as a Date table in the model).
// 2. The main fact table is called FactTable.
// 3. Dates[Date] 1:* FactTable[Date]

[YTD YoY %] =
// Dates[Date] is of the datetime datatype without
// the time component. It's the primary key in 
// the Dates table.
var vLastDayWithData =
    CALCULATE(
        MAX( FactTable[Date] ),
        REMOVEFILTERS( )
    )
var vYtdPeriod =
    // This logic is needed in order to get
    // correct comparisons for periods that
    // have not yet finished.
    CALCULATETABLE(
        DATESYTD(
            Dates[Date]
        ),
        KEEPFILTERS(
            Dates[Date] <= vLastDayWithData 
        )
    )
var vYtdPeriodLastYear = SAMEPERIODLASTYEAR( vYtdPeriod )
var vYtdValue =
    CALCULATE(
        [Measure],
        vYtdPeriod
    )
var vYtdValueLastYear =
    CALCULATE(
        [Measure],
        vYtdPeriodLastYear
    )
var vChange =
    DIVIDE(
        vYtdValue - vYtdValueLastYear,
        vYtdValueLastYear
    )
return
    vChange

 

 

 

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

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.

June 2025 community update carousel

Fabric Community Update - June 2025

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