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
cerebro
Helper I
Helper I

Address "previous" column value for measures

Dear community,

 

i would like to see the change in customer margins from month to month in a measure with the help of month number. 

The data is on a daily basis, previous month functions do not perform.

And ideally i would like to change the margin value into red or green if it goes up or down.

Can someone please help?

Thank you in advance.Power BI.png

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @cerebro ,

 

Do you want to display Revenue per customer on a monthly basis and show the growth rate compared to the previous month?

 

Here is my test and attached pbix file for your reference.

Margin = VAR currentMonth = MONTH(MAX('Table'[Date]))
VAR lastMonth = currentMonth-1
VAR cust = MAX('Table'[Customer])
VAR lastRev = CALCULATE(SUM('Table'[Revenue]),ALL('Table'),MONTH('Table'[Date])=lastMonth&&'Table'[Customer]=cust)
RETURN IF(CONTAINS(ADDCOLUMNS(ALL('Table'[Date]),"Month",MONTH('Table'[Date])),[Month],lastMonth),(SUM('Table'[Revenue])-lastRev)/lastRev)

The conditional formatting.

vmengmlimsft_0-1731651797633.png

 

 

Best regards,

Mengmeng Li

View solution in original post

5 REPLIES 5
Anonymous
Not applicable

Hi @cerebro ,

 

Do you want to display Revenue per customer on a monthly basis and show the growth rate compared to the previous month?

 

Here is my test and attached pbix file for your reference.

Margin = VAR currentMonth = MONTH(MAX('Table'[Date]))
VAR lastMonth = currentMonth-1
VAR cust = MAX('Table'[Customer])
VAR lastRev = CALCULATE(SUM('Table'[Revenue]),ALL('Table'),MONTH('Table'[Date])=lastMonth&&'Table'[Customer]=cust)
RETURN IF(CONTAINS(ADDCOLUMNS(ALL('Table'[Date]),"Month",MONTH('Table'[Date])),[Month],lastMonth),(SUM('Table'[Revenue])-lastRev)/lastRev)

The conditional formatting.

vmengmlimsft_0-1731651797633.png

 

 

Best regards,

Mengmeng Li

johnt75
Super User
Super User

Make sure that you have a properly formatted date table, marked as a date table. You can then create a measure like

Margin MoM % =
VAR CurrentMargin = [Margin]
VAR PrevMargin =
    CALCULATE ( [Margin], DATEADD ( 'Date'[Date], -1, MONTH ) )
VAR Result =
    DIVIDE ( CurrentMargin - PrevMargin, PrevMargin )
RETURN
    Result

thank you very much, the formula works but only with month number. our date table looks like this and i can not change anything about it, the whole data model was created by an IT consultant and i can only create measure in a dashboard.

Power BI1.PNG

Can you please modify the formula that it contains month number or maybe you have an idea how i can adresse the date in the table from the sceenshot?

I think that the formula I gave should still work, but if not you can try

Margin MoM % =
VAR CurrentMargin = [Margin]
VAR CurrentMonthNum =
    MAX ( 'Date'[Month] )
VAR PrevMargin =
    CALCULATE (
        [Margin],
        REMOVEFILTERS ( 'Date' ),
        VALUES ( 'Date'[Year] ),
        'Date'[Month] = CurrentMonthNum - 1
    )
VAR Result =
    DIVIDE ( CurrentMargin - PrevMargin, PrevMargin )
RETURN
    Result

unfortunately, the formula doesnt work, it says that this line

    'Date'[Month] = CurrentMonthNum - 1

compares two different types of data, text and number.

is there any way to just address the previous column without the data table?

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.