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
sara_pinto15
Frequent Visitor

Sum of the Sum

Hello,

 

I hope find you well.

 

I have a problem. 
To have the sum per line I used the measure:

.TotalValue_StatusY =
    CALCULATE(SUM(Table[Value]),
    'Table'[Status]="y",
    'Table'[Version]=MAX('Table'[Version])
    
But at the total level I have the sum of all values with status "y" when my purpose is to have only the sum of the latest version of status "y". 
Can you help me?
 
Example:
sara_pinto15_0-1703757652156.png

 

1 ACCEPTED SOLUTION
v-xiaodie-msft
Community Support
Community Support

Hi @sara_pinto15 ,

 

After understanding your problem, here is the solution I have for you.

 

This is the original table data. The name of the table is Table.

vxiaodiemsft_0-1703839051888.png

Create a measure that selects the maximum version of the ID with Status being y.

vxiaodiemsft_1-1703839051890.png

 

Measure = var _maxversion=CALCULATE(max('Table'[Version]), FILTER(ALLSELECTED('Table'),'Table'[ID]=SELECTEDVALUE('Table'[ID])&&  'Table'[Status]="y"))
    return CALCULATE(sum('Table'[Value]), FILTER( 'Table' ,  'Table'[Version]=_maxversion&&'Table'[Status]="y"))

 

 

Create another measure that shows the total value of the calculation.

vxiaodiemsft_2-1703839149181.png

 

TotalValue = SUMX(VALUES('Table'[ID]),[Measure])

 

 

Then the desired results can be achieved.

vxiaodiemsft_3-1703839175239.png

 

Best regards,

Erica Wu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

View solution in original post

9 REPLIES 9
v-xiaodie-msft
Community Support
Community Support

Hi @sara_pinto15 ,

 

After understanding your problem, here is the solution I have for you.

 

This is the original table data. The name of the table is Table.

vxiaodiemsft_0-1703839051888.png

Create a measure that selects the maximum version of the ID with Status being y.

vxiaodiemsft_1-1703839051890.png

 

Measure = var _maxversion=CALCULATE(max('Table'[Version]), FILTER(ALLSELECTED('Table'),'Table'[ID]=SELECTEDVALUE('Table'[ID])&&  'Table'[Status]="y"))
    return CALCULATE(sum('Table'[Value]), FILTER( 'Table' ,  'Table'[Version]=_maxversion&&'Table'[Status]="y"))

 

 

Create another measure that shows the total value of the calculation.

vxiaodiemsft_2-1703839149181.png

 

TotalValue = SUMX(VALUES('Table'[ID]),[Measure])

 

 

Then the desired results can be achieved.

vxiaodiemsft_3-1703839175239.png

 

Best regards,

Erica Wu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

This works perfectly! Thank you very much 😊

Dangar332
Super User
Super User

hi, @sara_pinto15 

@sara_pinto15 

 

 

 

measure =
   SUMX(
      FILTER(
        'Table','Table'[version ] =CALCULATE(MAX('Table'[version]), 
         'Table'[status]="y",ALLEXCEPT('Table','Table'[id]))
      ),
   'Table'[value]
   )

 

 

 

Dangar332_0-1703842028171.png

 

 

Thank you for your help. 
But this solution gives me this:

sara_pinto15_0-1703844945310.png

 

Thanks anyway 😊

 

Hi, @sara_pinto15 

 

with above data you provide my measure give as you want 

but it seems something another thing present in your real data.

see below screenshort

 

Dangar332_0-1703845257581.png

 

sjoerdvn
Super User
Super User

Try this:

TotalValue_StatusY =
    SUMX(VALUES(Table[ID]),
	CALCULATE(SUM('Table'[Value]),
    		'Table'[Status]="y",
    		'Table'[Version]=MAX('Table'[Version])))

Thank you for your help. 
But this solution gives me this:

sara_pinto15_3-1703845012133.png

 

 

Thanks anyway 😊

123abc
Community Champion
Community Champion

Certainly! Based on your description, you want to calculate the sum of values where the status is "y" but only for the latest version.

To achieve this, you can make use of the FILTER function along with the MAX function. Here's how you can modify your DAX measure to get the desired result:

 

.TotalValue_StatusY =
VAR MaxVersion = CALCULATE(MAX('Table'[Version]), 'Table'[Status] = "y")
RETURN
CALCULATE(
SUM('Table'[Value]),
'Table'[Status] = "y",
'Table'[Version] = MaxVersion
)

 

Here's a breakdown of what's happening in the measure:

  1. We first calculate the maximum version number where the status is "y" using the CALCULATE and MAX functions and store it in the variable MaxVersion.
  2. Then, using the CALCULATE function again, we filter the table to only consider rows where the status is "y" and the version matches the MaxVersion. Finally, we sum up the values for these filtered rows.

By using this measure, you should get the sum of values for the latest version where the status is "y".

 

If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly.

 

In case there is still a problem, please feel free and explain your issue in detail, It will be my pleasure to assist you in any way I can.

 

Thank you for your help. 
But this solution gives me this:

sara_pinto15_1-1703844980278.png

 

 

Thanks anyway 😊

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.