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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
brotha_lee
Regular Visitor

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?

1 ACCEPTED SOLUTION
Ashish_Mathur
Super User
Super User

Hi,

 

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

 

Hope this helps.

 

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

8 REPLIES 8
Ashish_Mathur
Super User
Super User

Hi,

 

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

 

Hope this helps.

 

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
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])))

 

Earlier.PNG

Thanks
Raj

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

Thanks that did the trick, however I now have the following issue,. I have a measure which calculates the YTD values based on the following formula:

YTD = round(CALCULATE('sum(ENT_SCD rptGLBalance'[amount]);filter(all('ENT_SCD dimAccountingPeriods'[AccountingPeriodKey]);'ENT_SCD dimAccountingPeriods'[AccountingPeriodKey]<=Max('ENT_SCD dimAccountingPeriods'[AccountingPeriodKey])));0).

 

when I use this measure in the column like:

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

it give me funny results. For example when I select accountingperiod "201802" the result is as follows:

AccountingPeriodProjectAmountYTDPROJ_TOTAL
201801X1010 
201802X-10-10-10

 

It looks like the PROJ_TOTAL is only calculating for the selected accountingperiod. Can this be solved?

 

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.

 

image.png

 

 

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
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)".

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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.