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
LEGIS
New Member

Summarize measure if another measure has value

Hi!

I need to summarize a measure, but only if another measure has any value (positive or negative).

I have measures 'Energy' and 'stocked' (both calculated).  I need to summarize 'Energy', but only those rows that has any value on 'stocked'.

For instance, in this case it should summarize 'Energy' only for months May and August (it's in Spanish on the table). The result should be 2659 (1784+875).

LEGIS_0-1605643822199.png

 

How can I do this?

 

I've tried this calculation that at row level works, but in the total it shows me the sum of everything:

SUMX(Table,
IF(Table[stocked]>0,[Energy],BLANK())
)
LEGIS_0-1605644908867.png

(the total should be 2659(1784+875)

 
 

 

 

Thanks in advance

 

1 ACCEPTED SOLUTION
PaulDBrown
Community Champion
Community Champion

@LEGIS 

ok, based on the information (fields in the visual) try:

 

 

Measure =
SUMX (
    FILTER (
        SUMMARIZE ( //This creates a virtual table with the rows in the visual and the agregated value for [Stocked] by row
            'Table',
            'Table'[Year],
            'Table'[Month],
            "FilteredST", [Stocked]
        ),
        [FilteredST] > 0 //This filters the virtual table to only show the rows whose aggregated [Stocked] value is greater than 0
    ),
    [Energy] //Returns the sum of the value for [energy] for the rows filtered in the virtual table
)

 

 





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






View solution in original post

7 REPLIES 7
v-yangliu-msft
Community Support
Community Support

Hi  @LEGIS ,

Here are the steps you can follow:

1. Create measure.

Measure 2 =
var _new=SUMMARIZE('Table','Table'[year],"Value",[Measure])
return IF(HASONEVALUE('Table'[year]),[Measure],SUMX(_new,[Value]))

2. Result.

v-yangliu-msft_0-1605747252887.png

You can downloaded PBIX file from here.

 

Best Regards,

Liu Yang

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

PaulDBrown
Community Champion
Community Champion

@LEGIS 

Try:

Measure =

SUMX(FILTER(Table, [Stocked]> 0), [Energy])





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






Hi Paul!
Thanks for your help. 

I've just tried that, but the total keeps summarizing all rows:

LEGIS_0-1605702381721.png

 

PaulDBrown
Community Champion
Community Champion

@LEGIS 

ok, based on the information (fields in the visual) try:

 

 

Measure =
SUMX (
    FILTER (
        SUMMARIZE ( //This creates a virtual table with the rows in the visual and the agregated value for [Stocked] by row
            'Table',
            'Table'[Year],
            'Table'[Month],
            "FilteredST", [Stocked]
        ),
        [FilteredST] > 0 //This filters the virtual table to only show the rows whose aggregated [Stocked] value is greater than 0
    ),
    [Energy] //Returns the sum of the value for [energy] for the rows filtered in the virtual table
)

 

 





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






Thank you so much Paul!

This worked, I've already marked it as the solution 😁



Sorry for making a nuisance of myself, but my 'Year' and 'Month' fields both are from different tables.

Is there a way to include both tables in the filter?

PaulDBrown
Community Champion
Community Champion

@LEGIS 

In theory yes, as long as they are related. Do you have a mockup/depiction of the model view and the relationships?





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






If one table is unrelated?

 

 

I have three tables. Two of them are related and one table is unrelated.

 

But the unrelated table can be connected to the main table by creating concatenation columns: one in the main table and one in the unrelated table.

 

But the obstacle I have is that i am not allowed to use:  calculated tables, calculated columns, power query(m language) and change relationships in the data model. I am.inly allowed to use measures.

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.