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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Anonymous
Not applicable

Calculate the sum of specifit rows

I have following table:

 

 SalesCOGSProfit
January1000500500
February1000500500
March20005001500
April30005002500
May40005003500
June50005004500
July60005005500
August600010005000
September600010005000
October600010005000
November600010005000
December600010005000

 

Now i want to create

1. a new measure of sum of profit from March to December forecast.

2. Another measure of sum of profit from January to February as an actual value.

 

Then put these two new measure together in a line chart to see the actual and forecast together.

 

I am bit lost about how to do this, could anyon please help? Thank you in advance 🙂

1 ACCEPTED SOLUTION
helassal
Resolver II
Resolver II

@Anonymous ,

 

Hi there,

 

You can write the measures like that:

 

m_ActualProfit = if( min('Table'[Month]) in {"January","February"}, CALCULATE(SUM('Table'[Profit])))

m_ForecastProfit = if( NOT(MIN('Table'[Month]) IN {"January","February"}), CALCULATE(SUM('Table'[Profit])))

 

And then display them in  a chart like that:

 

ActualForecast.png

 

BUT, I would like to suggest few enhancements to the way you are shaping the data in your data model, here are some pointers:

1- Try to use an actual date instead of the month name, the reason for that is that it makes it easier to do the following:

     a- Write dynamic date filters instead of static ones, for example the m_ActualProfit could then be written like that:

m_ActualProfit = if( MIN('Table'[MonthAsDate]) < DATE(YEAR(NOW()),MONTH(NOW()),1), CALCULATE(SUM('Table'[Profit])))

    b- To be able to get the months sorted correctly in the chart instead of having to explicitly add a Month No column and use it to sort Month name.

2- You can even go a bit further and create a date dimension in your data model if you are going to build more complex reporting based on that data model.

   Refs:

        https://radacad.com/create-a-date-dimension-in-power-bi-in-4-steps-step-1-calendar-columns

        https://docs.microsoft.com/en-us/power-bi/desktop-date-tables

        https://docs.microsoft.com/en-us/power-bi/desktop-auto-date-time

 

Hope this helps.

 

Best Regards,

Haitham

View solution in original post

1 REPLY 1
helassal
Resolver II
Resolver II

@Anonymous ,

 

Hi there,

 

You can write the measures like that:

 

m_ActualProfit = if( min('Table'[Month]) in {"January","February"}, CALCULATE(SUM('Table'[Profit])))

m_ForecastProfit = if( NOT(MIN('Table'[Month]) IN {"January","February"}), CALCULATE(SUM('Table'[Profit])))

 

And then display them in  a chart like that:

 

ActualForecast.png

 

BUT, I would like to suggest few enhancements to the way you are shaping the data in your data model, here are some pointers:

1- Try to use an actual date instead of the month name, the reason for that is that it makes it easier to do the following:

     a- Write dynamic date filters instead of static ones, for example the m_ActualProfit could then be written like that:

m_ActualProfit = if( MIN('Table'[MonthAsDate]) < DATE(YEAR(NOW()),MONTH(NOW()),1), CALCULATE(SUM('Table'[Profit])))

    b- To be able to get the months sorted correctly in the chart instead of having to explicitly add a Month No column and use it to sort Month name.

2- You can even go a bit further and create a date dimension in your data model if you are going to build more complex reporting based on that data model.

   Refs:

        https://radacad.com/create-a-date-dimension-in-power-bi-in-4-steps-step-1-calendar-columns

        https://docs.microsoft.com/en-us/power-bi/desktop-date-tables

        https://docs.microsoft.com/en-us/power-bi/desktop-auto-date-time

 

Hope this helps.

 

Best Regards,

Haitham

Helpful resources

Announcements
PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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