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
Syndicate_Admin
Administrator
Administrator

Variation from previous period (discontinuous periods)

Good afternoon, the company where I work I need to make a report with the percentage variation in raw materials over the last three years. The downside is that raw materials don't go up every month so there are months when I don't have data.

Raw material value table

Columns: Year/month

Rows: Prices of different raw materials

flitvak_0-1616788291671.png

The table shows that for example during October and November 2020 there was no price update.

For cases where there are ups in consecutive months, I had no problem getting the %

flitvak_1-1616788674168.png

In other words, in this case I would be short to obtain the percentage change between September 2020 and December 2020 (among several other periods).

From now on I appreciate any contribution!!!

Best regards

1 ACCEPTED SOLUTION
Anonymous
Not applicable

HI @flitvak,

I think you may need to use Dax function to find out the last date that existed valid value in your table, then you can use this with the current category value to lookup corresponding value to compare with current and previous values.

 

measure =
VAR currDate =
    MAX ( Table[Date] )
VAR prevDate =
    CALCULATE (
        MAX ( Table[Date] ),
        FILTER ( ALLSELECTED ( Table ), [Date] < currDate && [Amount] <> BLANK () ),
        VALUES ( Table[Category] )
    )
VAR prevAmount =
    CALCULATE (
        SUM ( Table[Amount] ),
        FILTER ( ALLSELECTED ( Table ), [Date] = prevDate ),
        VALUES ( Table[Category] )
    )
RETURN
    DIVIDE ( SUM ( Table[Amount] ) - prevAmount, prevAmount )

 

Regards,

Xiaoxin Sheng

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

HI @flitvak,

I think you may need to use Dax function to find out the last date that existed valid value in your table, then you can use this with the current category value to lookup corresponding value to compare with current and previous values.

 

measure =
VAR currDate =
    MAX ( Table[Date] )
VAR prevDate =
    CALCULATE (
        MAX ( Table[Date] ),
        FILTER ( ALLSELECTED ( Table ), [Date] < currDate && [Amount] <> BLANK () ),
        VALUES ( Table[Category] )
    )
VAR prevAmount =
    CALCULATE (
        SUM ( Table[Amount] ),
        FILTER ( ALLSELECTED ( Table ), [Date] = prevDate ),
        VALUES ( Table[Category] )
    )
RETURN
    DIVIDE ( SUM ( Table[Amount] ) - prevAmount, prevAmount )

 

Regards,

Xiaoxin Sheng

Thank you very much Xiaoxin for the help!!! It was just what I needed!!!

As a whole I adapted the date in the currDate variable and it worked perfectly. The code looked like this to me:

% Increase ?
VAR currDate =
MAX ( OCA[Date of Issue] )
VAR prevDate =
CALCULATE (
MAX ( 'Calendar Table'[Date] );
FILTER ( ALLSELECTED ('Calendar Table'); 'Calendar table'[Date] < currDate && [MAX price] <> BLANK() );
VALUES ( OCA[Article] )
)
VAR prevAmount =
CALCULATE (
max(OCA[Unit price without discounts UM purchases]);
FILTER ( ALLSELECTED ( 'Calendar Table' ); 'Calendar table'[Date] ? prevDate );
VALUES ( OCA[Article] )
)
RETURN
DIVIDE ( max(OCA[Unit price without discounts UM purchases]) - prevAmount; prevAmount )

Anonymous
Not applicable

Hi @flitvak,

I'm glad to hear my formula helps. 😊

If you have any other requirements, you can feel free to post here with detailed information.
Regards,

Xiaoxin Sheng

lbendlin
Super User
Super User

Have a separate table with all the months (preferably a proper calendar table)  and then create a measure that calculates for each month what the latest price update is (either for the current month or for the max month that is smaller than the current month).

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.