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
Anonymous
Not applicable

Calculate a conditional sum per month

Hello,

 

I have a table with a [Date] field and the following measure:

Monthly_sum=
CALCULATE (
COUNTROWS ( 'History_table' ),
FILTER (
'History_table',
CONTAINSSTRING(([Closure Strategy]), "CAT 1") || CONTAINSSTRING(([Closure Strategy]), "CAT 2")
)
)

 

On X axis I put [Date] and values are the measure above. I want to count the number of [id] per month that meet the criteria above.

The problem is that the measure it is not broken down by each month but it is a total that is displayed for all months (the same value)

 

image.png

 

Please advise.

Regards

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Thank you Ibendlin, I am revising the answer, it WORKS ! I made a mistake in regards of filters.

Marked as solution!

View solution in original post

3 REPLIES 3
v-yangliu-msft
Community Support
Community Support

Hi  @Anonymous ,

According to your description, I create this data:

v-yangliu-msft_2-1615193924505.png

Here are the steps you can follow:

1. Create measure.

Measure =
CALCULATE(
    COUNTROWS('History_table'),
FILTER(ALL('History_table'),
    OR(
        CONTAINSSTRING('History_table'[Closure Strategy],"CAT 1"),
        CONTAINSSTRING('History_table'[Closure Strategy],"CAT 2"))
        &&
        'History_table'[Year]=MAX('History_table'[Year])
        &&
        'History_table'[month]=MAX('History_table'[month])))

2. Result:

v-yangliu-msft_3-1615193924508.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.

lbendlin
Super User
Super User

Monthly_sum=
CALCULATE (
COUNTROWS ( 'History_table' ),

ALLEXCEPT(DatesTable,DatesTable[Month]),
FILTER (
'History_table',
CONTAINSSTRING(([Closure Strategy]), "CAT 1") || CONTAINSSTRING(([Closure Strategy]), "CAT 2")
)
)

Anonymous
Not applicable

Thank you Ibendlin, I am revising the answer, it WORKS ! I made a mistake in regards of filters.

Marked as solution!

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.