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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
Anonymous
Not applicable

Efficient ways of counting different metrics values using DAX?

I have a project table in my data model, with all 10 metrics (calculated columns) are calculated using DAX. For each metric, there are three different values: 1 (means good), 2 (means warning), and 3 (means bad).  Let's say project A has 3 good metric, 3 warning metric, and 4 bad metric. I want to create calculated column for each good, warning, and bad category such that the result will be showing: 

 

Metrics.PNG


Right now my calculate column for Good category is as follow: 

Good = CALCULATE(COUNT(Project[Metric1], Project[Metric1] = 1) + CALCULATE(COUNT(Project[Metric2], Project[Metric2] = 1) + ... + CALCULATE(COUNT(Project[Metric10], Project[Metric10] = 1), and so on. 

 

Is there a more efficent way to write the above DAX expression?

2 ACCEPTED SOLUTIONS
Zubair_Muhammad
Community Champion
Community Champion

Hi @Anonymous

 

Another way could be

 

Good =
VAR Temp = {
        Project[Metric 1],
        Project[Metric 2],
        Project[Metric 3],
        Project[Metric 4],
        Project[Metric 5],
        Project[Metric 6],
        Project[Metric 7],
        Project[Metric 8],
        Project[Metric 9],
        Project[Metric 10] }
RETURN
    COUNTROWS ( FILTER ( Temp, [Value] = 1 ) )

Regards
Zubair

Please try my custom visuals

View solution in original post

@Anonymous

 

For Bad and Warning... you will just have to change single Value

 

Warning =
VAR Temp = {
        Project[Metric 1],
        Project[Metric 2],
        Project[Metric 3],
        Project[Metric 4],
        Project[Metric 5],
        Project[Metric 6],
        Project[Metric 7],
        Project[Metric 8],
        Project[Metric 9],
        Project[Metric 10] }
RETURN
    COUNTROWS ( FILTER ( Temp, [Value] = 2 ) )

Regards
Zubair

Please try my custom visuals

View solution in original post

2 REPLIES 2
Zubair_Muhammad
Community Champion
Community Champion

Hi @Anonymous

 

Another way could be

 

Good =
VAR Temp = {
        Project[Metric 1],
        Project[Metric 2],
        Project[Metric 3],
        Project[Metric 4],
        Project[Metric 5],
        Project[Metric 6],
        Project[Metric 7],
        Project[Metric 8],
        Project[Metric 9],
        Project[Metric 10] }
RETURN
    COUNTROWS ( FILTER ( Temp, [Value] = 1 ) )

Regards
Zubair

Please try my custom visuals

@Anonymous

 

For Bad and Warning... you will just have to change single Value

 

Warning =
VAR Temp = {
        Project[Metric 1],
        Project[Metric 2],
        Project[Metric 3],
        Project[Metric 4],
        Project[Metric 5],
        Project[Metric 6],
        Project[Metric 7],
        Project[Metric 8],
        Project[Metric 9],
        Project[Metric 10] }
RETURN
    COUNTROWS ( FILTER ( Temp, [Value] = 2 ) )

Regards
Zubair

Please try my custom visuals

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.