Forum Discussion

reinholz's avatar
reinholz
Frequent Visitor
9 years ago
Solved

How to dynamically calculate customer margin by month?

Hey!   I'm fairly new to Power BI and DAX and I need help with a matrix table I want to create. I tried different approaches but can't figure out how to make it work.   Here is what I want to do...
  • v-ljerr-msft's avatar
    9 years ago

    reinholz

     

    According to your description, you should be able to use SUM function to sum up the costs by customer and month and subtract it from the monthly subscription price in your scenario. See my sample below.

     

    I assume you have tables like below.

    Costs

    Customer

    Date

    Then you should be able to use the formula below to create the measure and show it in the Matrix.

    Margin =
    IF (
        MAX ( 'Date'[Date] ) <= MAX ( Customer[end date] )
            || SUM ( Costs[amount] ) = BLANK (),
        (
            CALCULATE ( MAX ( Customer[monthly subscription price] ), ALL ( 'Date' ) )
                - IF ( ISBLANK ( SUM ( Costs[amount] ) ), 0, SUM ( Costs[amount] ) )
        )
            / CALCULATE ( MAX ( Customer[monthly subscription price] ), ALL ( 'Date' ) )
    )

    Regards