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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
enoch99
Helper I
Helper I

Distinct Count by comparing two summarized tables

Hi everyone,

 

I am new to DAX and need your support in solving this problem. 

 

I have two Excel files. One contains yearly target planned for different activities while the second contains monthly reports of reached. I want to count those activities that are lagging behind. 

 

1. 

enoch99_1-1691658802526.png

 

2. 

enoch99_2-1691658884054.png

 

I tried to do smoething like this but I got lost in the middle:

var maxMonth = MAX('Reached'[month])
var target_table =SUMMARIZE('Target', 'Target'[Activity], "Monthly Target", CALCULATE ( DIVIDE(SUM( 'Target'[Target] ),12,0)))
var beneficiary_table = SUMMARIZE('Reached', 'Reached'[Activity], "Monthly Reached", CALCULATE ( DIVIDE(SUM( 'Reached'[Reached] ),maxMonth,0)))

 

What I want is a measure that distinct counts activities that are lagging behind ie. Monthly Target > Monthly Reached.

 

I would very much appreacite your help.

 

Thank you

 

1 ACCEPTED SOLUTION

@enoch99 You can create a calculated column in Target table

 

 

Reached =
SUMX (
    FILTER ( Reached, [Activity] = EARLIEST ( Target[Activity] ) ),
    [Reached]
)

 

nandukrishnavs_0-1691670469266.png

If you need a measure, then try the below measure

Lagging = 
VAR _target =
    ADDCOLUMNS (
        Target,
        "@Reached",
            SUMX (
                FILTER ( Reached, [Activity] = EARLIER ( Target[Activity] ) ),
                [Reached]
            )
    )
VAR _result =
    COUNTX ( FILTER ( _target, [@Reached] < [Target] ), [Activity] )
RETURN
    _result

Regards,
Nandu Krishna

View solution in original post

4 REPLIES 4
nandukrishnavs
Community Champion
Community Champion

@enoch99 based on above dataset, what is the expected result. Can you mention that as well?


Regards,
Nandu Krishna

@nandukrishnavsI want a table like this:

enoch99_1-1691668379032.png

 

I think I can compare the Target and Reached columns after that to count the number of activities lagging behind.

 

Thanks

@enoch99 You can create a calculated column in Target table

 

 

Reached =
SUMX (
    FILTER ( Reached, [Activity] = EARLIEST ( Target[Activity] ) ),
    [Reached]
)

 

nandukrishnavs_0-1691670469266.png

If you need a measure, then try the below measure

Lagging = 
VAR _target =
    ADDCOLUMNS (
        Target,
        "@Reached",
            SUMX (
                FILTER ( Reached, [Activity] = EARLIER ( Target[Activity] ) ),
                [Reached]
            )
    )
VAR _result =
    COUNTX ( FILTER ( _target, [@Reached] < [Target] ), [Activity] )
RETURN
    _result

Regards,
Nandu Krishna

@nandukrishnavs  Thank you for your quick response. This is what I was looking for.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.