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
PBI_newuser
Post Prodigy
Post Prodigy

How to remove duplicates count

Hi, have created some measures in this sample pbix file. If a product is valid for both "Contract" & Warranty" in the same period, how to count only "Warranty" for that product. (E.g. Product A in 2022-02 and Product D in 2022-03) If a product is valid for both "Rental" & "Warranty" in the same month, how to count only "Warranty" for that product. (E.g. Product B in 2022-02)

 

Besides, the sum for T&M is incorrect? How to fix it?

PBI_newuser_0-1649211003057.png

 

 

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

Hi @PBI_newuser ,

Please refer to my pbix file to see if it helps you.

Create measures.

contract_ = var answer_=CALCULATE(DISTINCTCOUNT('Product'[Product]), filter('Product',  'Product'[Installed Date]<= max('Calendar'[Date]) && 'Product'[Contract Start Date] <= max('Calendar'[Date]) && 'Product'[Contract End Date] >= min('Calendar'[Date]) && 'Product'[Term]="Purchased" ) )
return
IF(answer_=[Warranty],BLANK(),answer_)
_contract_ = var _a = 'Product'[contract_]
var _b = SUMMARIZE('Product','Product'[Product],"aaa",'Product'[contract_])
return
IF(HASONEVALUE('Product'[Product]),_a,SUMX(_b,[aaa]))
T&M = CALCULATE(DISTINCTCOUNT('Product'[Product]), filter(ALL('Product'), ('Product'[Installed Date] <= max('Calendar'[Date]) && 'Product'[Contract Start Date] = BLANK()) || ('Product'[Contract Start Date]<>BLANK() && Max('Product'[Contract End Date]) < min('Calendar'[Date]))))
Measure = var _a = [T&M]
var _b = SUMMARIZE('Product','Product'[Product],"aaa",[T&M])
return
IF(HASONEVALUE('Product'[Product]),_a,SUMX(_b,[aaa]))

vpollymsft_0-1649400836357.png

 

 

If I have misunderstood your meaning, please provide your desired output with a screenshoot.

 

Best Regards

Community Support Team _ Polly

 

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

6 REPLIES 6
v-rongtiep-msft
Community Support
Community Support

Hi @PBI_newuser ,

Does that make sense? If so, kindly mark my answer as the solution to close the case please. Thanks in advance.

 

If I have misunderstood your meaning, please provide your desired output with a screenshoot.

 

Best Regards

Community Support Team _ Polly

v-rongtiep-msft
Community Support
Community Support

Hi @PBI_newuser ,

Please refer to my pbix file to see if it helps you.

Create measures.

contract_ = var answer_=CALCULATE(DISTINCTCOUNT('Product'[Product]), filter('Product',  'Product'[Installed Date]<= max('Calendar'[Date]) && 'Product'[Contract Start Date] <= max('Calendar'[Date]) && 'Product'[Contract End Date] >= min('Calendar'[Date]) && 'Product'[Term]="Purchased" ) )
return
IF(answer_=[Warranty],BLANK(),answer_)
_contract_ = var _a = 'Product'[contract_]
var _b = SUMMARIZE('Product','Product'[Product],"aaa",'Product'[contract_])
return
IF(HASONEVALUE('Product'[Product]),_a,SUMX(_b,[aaa]))
T&M = CALCULATE(DISTINCTCOUNT('Product'[Product]), filter(ALL('Product'), ('Product'[Installed Date] <= max('Calendar'[Date]) && 'Product'[Contract Start Date] = BLANK()) || ('Product'[Contract Start Date]<>BLANK() && Max('Product'[Contract End Date]) < min('Calendar'[Date]))))
Measure = var _a = [T&M]
var _b = SUMMARIZE('Product','Product'[Product],"aaa",[T&M])
return
IF(HASONEVALUE('Product'[Product]),_a,SUMX(_b,[aaa]))

vpollymsft_0-1649400836357.png

 

 

If I have misunderstood your meaning, please provide your desired output with a screenshoot.

 

Best Regards

Community Support Team _ Polly

 

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

v-rongtiep-msft
Community Support
Community Support

Hi @PBI_newuser ,

Please refer to my pbix file to see if it helps you.

Please modify the formula of contract and TM.

contract_ =
VAR answer_ =
    CALCULATE (
        DISTINCTCOUNT ( 'Product'[Product] ),
        FILTER (
            'Product',
            'Product'[Installed Date] <= MAX ( 'Calendar'[Date] )
                && 'Product'[Contract Start Date] <= MAX ( 'Calendar'[Date] )
                && 'Product'[Contract End Date] >= MIN ( 'Calendar'[Date] )
                && 'Product'[Term] = "Purchased"
        )
    )
RETURN
    IF ( answer_ = [Warranty], BLANK (), answer_ )
T&M =
CALCULATE (
    DISTINCTCOUNT ( 'Product'[Product] ),
    FILTER (
        ALL ( 'Product' ),
        (
            'Product'[Installed Date] <= MAX ( 'Calendar'[Date] )
                && 'Product'[Contract Start Date] = BLANK ()
        )
            || (
                'Product'[Contract Start Date] <> BLANK ()
                    && MAX ( 'Product'[Contract End Date] ) < MIN ( 'Calendar'[Date] )
            )
    )
)

vpollymsft_0-1649385796508.png

If I have misunderstood your meaning, please provide your desired output with a screenshoot.

 

Best Regards

Community Support Team _ Polly

 

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

 

Hi @v-rongtiep-msft , thank you for your help! The measure "contract_" looks good but the sum is incorrect. The sum for contract_ for 2022-02 shows 2 but it should be 1.

For T&M, I want to count the product if they have expired contract. Below measure seems correct but the sum is incorrect. How to fix it?

 

T&M = CALCULATE(DISTINCTCOUNT('Product'[Product]), 
filter('Product',
(
'Product'[Installed Date] <= max('Calendar'[Date]) && 'Product'[Contract Start Date] = BLANK()) ||
(
'Product'[Contract Start Date]<>BLANK() && Max('Product'[Contract End Date]) < min('Calendar'[Date]))))

PBI_newuser_0-1649389864531.png

 

amitchandak
Super User
Super User

@PBI_newuser , Please provide access to the file

 

refer why grand total is wrong

https://www.youtube.com/watch?v=ufHOOLdi_jk

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.

Top Solution Authors