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
Mister_T
Advocate I
Advocate I

[DAX Measure] Correct values, but wrong total

Dear Community,

again, I am lost in the depth of Power BI and DAX. Any help greatly appreciated!


I have the following table 'Sales':

 

Deal ID

Deal Closed

Deal Won

Reseller

001

FALSE

FALSE

A

002

TRUE

FALSE

B

002

TRUE

FALSE

B

002

TRUE

FALSE

C

003

FALSE

FALSE

A

004

TRUE

FALSE

B

005

TRUE

TRUE

A

005

TRUE

TRUE

A

006

TRUE

TRUE

B

007

TRUE

FALSE

A

007

TRUE

FALSE

A

007

TRUE

FALSE

C

008

TRUE

FALSE

A

 

To find out, which reseller was involved in how many deals close lost, I have created the following measure (using help from this thread).

Please note: For one and the same deal (same Deal ID) it might happen, that

  • one reseller is listed several times --> then this reseller should only be counted once per deal
  • the deal is handled by more than one reseller --> then each of the resellers involved in the deal should be counted once
COUNT_Reseller_Lost = 
CALCULATE (
    DISTINCTCOUNT ( 'Sales'[Deal ID] ),
    FILTER (
        ALLEXCEPT ( 'Sales', 'Sales'[Reseller] ),
        'Sales'[Deal Closed] = TRUE ()
            && 'Sales'[Deal Won] = FALSE ()
        )
    )

 

This measure brings me the ring counts for each reseller, but unfortunately, the total is wrong!

Mister_T_0-1618571639803.png

How to I have to adjust the measure, that both the values for each Reseller and the Total are displayed correctly?

 

Thank you very much!

 

Mister_T

1 ACCEPTED SOLUTION
ERD
Super User
Super User

Hi @Mister_T ,

Create a second measure:

 

#Result = 
IF(HASONEVALUE('Sales'[Reseller]),
[COUNT_Reseller_Lost],
SUMX(VALUES('Sales'[Reseller]), [COUNT_Reseller_Lost])
)

 

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

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

Check out my latest demo report in the data story gallery.

Stand with Ukraine!


Here are official ways you can support Ukraine financially (accounts with multiple currencies):
1) Support the Armed Forces of Ukraine: https://bank.gov.ua/ua/about/support-the-armed-forces
2) Come Back Alive foundation: https://www.comebackalive.in.ua/

Thank you!

View solution in original post

6 REPLIES 6
ERD
Super User
Super User

Hi @Mister_T ,

Create a second measure:

 

#Result = 
IF(HASONEVALUE('Sales'[Reseller]),
[COUNT_Reseller_Lost],
SUMX(VALUES('Sales'[Reseller]), [COUNT_Reseller_Lost])
)

 

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

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

Check out my latest demo report in the data story gallery.

Stand with Ukraine!


Here are official ways you can support Ukraine financially (accounts with multiple currencies):
1) Support the Armed Forces of Ukraine: https://bank.gov.ua/ua/about/support-the-armed-forces
2) Come Back Alive foundation: https://www.comebackalive.in.ua/

Thank you!

Thank you @ERD!

 

Works like a charm! 🙂

Thanks again for your help! Greatly appreciated.

amitchandak
Super User
Super User

@Mister_T , Try

COUNT_Reseller_Lost =
CALCULATE (
DISTINCTCOUNT ( 'Sales'[Deal ID] ),
FILTER ('Sales' ,
coalesce(CALCULATE(Max('Sales'[Deal Closed]) , ALLEXCEPT ( 'Sales', 'Sales'[Deal ID] )), false()) =True(),
&& 'Sales'[Deal Won] = FALSE ()
)
)

Hi @amitchandak,

 

Thank you very much!

Unfortunately, your DAX formula returns
"The syntax for '&&' is incorrect. (DAX(CALCULATE (DISTINCTCOUNT ( 'Sales'[Deal ID] ),FILTER ('Sales' ,coalesce(CALCULATE(Max('Sales'[Deal Closed]) , ALLEXCEPT ( 'Sales', 'Sales'[Deal ID] )), false()) =True(),&& 'Sales'[Deal Won] = FALSE ()))))."

 

Deleting the ',' after "TRUE ()",

 

COUNT_Reseller_Lost_NEW = 
CALCULATE (
    DISTINCTCOUNT ( 'Sales'[Deal ID] ),
    FILTER ('Sales' ,
        COALESCE (
            CALCULATE(
                Max('Sales'[Deal Closed]) ,
                ALLEXCEPT ( 'Sales', 'Sales'[Deal ID] )
                ),
            FALSE ()
            )
        =TRUE ()
        && 'Sales'[Deal Won] = FALSE ()
        )
    )

 


lets the formula pass as measure, but as soon as I want to use it in a vizual, I get the error message

Mister_T_0-1618575772544.png


Any alternative to 'MAX' when it cannot work with BOOLEAN?

Thanks a lot!

 

@Mister_T , Try like

COUNT_Reseller_Lost_NEW = CALCULATE ( DISTINCTCOUNT ( 'Sales'[Deal ID] ), FILTER ('Sales' , COALESCE ( CALCULATE( Count('Sales'[Deal Closed]), 'Sales'[Deal Closed] = TRue() , ALLEXCEPT ( 'Sales', 'Sales'[Deal ID] ) ), 0 ) <>0 && 'Sales'[Deal Won] = FALSE () ) )

Thank you, @amitchandak! Your help is greatly appreciated.

Unfortunatelly, here again, I get an error message, when using this measure as value for a table (or any other) visual:

Mister_T_0-1618814070857.png


"The function COUNT cannot work with values of type Boolean."

 

Best regards,

 

Mister_T

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.