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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

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
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

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