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

Count if value appears at least once a month and get toal of number of months it has appeard

I have a dataset with all hours logged by each person for each project, i.e. something like this:

artjomsf_0-1685963434822.png

 

I need to get a small summary table to count all employees who have logged Project A at least once per month and in the end count how many of those months were in total (in the period I select with sliced).

 

My current formula looks like this:

Measure = CALCULATE( 
DISTINCTCOUNT(Data[Name]),
FILTER(Data, CALCULATE( SUM(Data[Hours]), FILTER(Data, Data[Project] = "Prj A"))
> 0)
)

 

Then I aggregate in the matrix with Names as rows and months as columns. It partially works, giving me correct count (1 or blank):

artjomsf_1-1685963816491.png

 

But it: a) does not give me total count (so I cannot sort by total) and b) seems to be extremely slow.

 

How would it be possible to improve this formula?

 

Thanks!

 

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

Hi @artjomsf ,

 

You can try using the SUMX function instead of SUM to improve the performance of your formula.

Measure = CALCULATE(
DISTINCTCOUNT(Data[Name]),
FILTER(Data,
SUMX(
FILTER(Data, Data[Project] = "Prj A"),
Data[Hours]
) > 0
)
)

To get the total count, you can create another measure 2 instead of measure.

Measure2 =
SUMX(
SUMMARIZE(
'Data',
'Data'[ColumnName],
"total",[Measure]
),
[total]
)

Best Regards,

Neeko Tang

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

1 REPLY 1
v-tangjie-msft
Community Support
Community Support

Hi @artjomsf ,

 

You can try using the SUMX function instead of SUM to improve the performance of your formula.

Measure = CALCULATE(
DISTINCTCOUNT(Data[Name]),
FILTER(Data,
SUMX(
FILTER(Data, Data[Project] = "Prj A"),
Data[Hours]
) > 0
)
)

To get the total count, you can create another measure 2 instead of measure.

Measure2 =
SUMX(
SUMMARIZE(
'Data',
'Data'[ColumnName],
"total",[Measure]
),
[total]
)

Best Regards,

Neeko Tang

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

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.