Forum Discussion

brotha_lee's avatar
brotha_lee
Regular Visitor
8 years ago
Solved

SUMIF / DAX

Hi,

I am new to DAX but I am struggling with a very simple question.

I have the following table:

AccountingPeriodProjectAmount
201801X10
201802X-10
201803 20
201803Y50
201803Y0

 

What I want is to add a measure which calculate the total a project (over the entire selection). So the output should be like this:

AccountingPeriodProjectAmountProject Total
201801X100
201802X-100
201803 2020
201803Y5050
201803Y050

 

I can't seem to get it working! Can anybody help?

8 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Frankly, the output you want is a bit misleading to the viewer. What does each line represent? You could try doing a matrix instead of a table, and set your rows to have a hierarchy of Project => Accounting Period. If you do this, you'll see the amount for each accounting period after a single drilldown, as well as row subtotals that will give you the data you're after. I'm assuming the last accounting periods are supposed to be different, or those are otherwise individual line items that you can delineate with an identifier.

     

     

     

    • brotha_lee's avatar
      brotha_lee
      Regular Visitor

      Thanks for the reply. I can understand your comment, that it can be misleading, however I want to use the measure to filter out all the enrties for which the projects have a 0 balance. The matrix solution unfortunately is not possible, as the user want to see all detailed lines (transactions) at once, instead of drilling up and down.

      • Anonymous's avatar
        Anonymous
        Not applicable

        In that case, you can leverage the interactivity of Power BI. On one table or chart (for example a bar chart), you have a listing of projects with their aggregate balance. This can be done easily out of the box, and you can filter that visual to have a sum of Amount greater than zero, or not equal to zero. Once the user clicks on any projects there, a table showing the individual transactions will be filtered to that project.

         

        If you really need to, you can use CALCULATE with a simple SUM on Amount, and a filter that compares "Project" to "EARLIER(Project)".

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi

     

    This will help you.

     

    Proj_total = CALCULATE(SUM(Ex_Over[Amount]), FILTER(Ex_Over,Ex_Over[Project]=EARLIER(Ex_Over[Project])))

     

    Thanks
    Raj

    • brotha_lee's avatar
      brotha_lee
      Regular Visitor

      Thanks for the response however I get the following error when using the formula:

      EARLIER/EARLIEST refers to an earlier row context which doesn't exist.

      How can I solve this / Am I doing something wrong?

       

      Here is my formula with the table names: 

      PROJ_TOTAL = CALCULATE(SUM('ENT_SCD rptGLBalance'[Amount]);FILTER('ENT_SCD rptGLBalance';'ENT_SCD rptGLBalance'[Project]=EARLIER('ENT_SCD rptGLBalance'[Project])))

      • Anonymous's avatar
        Anonymous
        Not applicable

         


        brotha_lee wrote:

        Thanks for the response however I get the following error when using the formula:

        EARLIER/EARLIEST refers to an earlier row context which doesn't exist.

        How can I solve this / Am I doing something wrong?

         

        Here is my formula with the table names: 

        PROJ_TOTAL = CALCULATE(SUM('ENT_SCD rptGLBalance'[Amount]);FILTER('ENT_SCD rptGLBalance';'ENT_SCD rptGLBalance'[Project]=EARLIER('ENT_SCD rptGLBalance'[Project])))



        Create as a calculated column, not as measure. You will not get the error.

         

        Thanks
        Raj

  • Hi,

     

    Here is the result i got.  You may download the PBI file from here.

     

    Hope this helps.