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
msuser48
Helper I
Helper I

Can't divide by DISTINCTCOUNTNOBLANK

When applying the following code to generate "PostCounter", I get the correct output:

msuser48_0-1670263880177.pngmsuser48_1-1670263906699.png

 

Issue: I need to divide not by the static "2" value, but by DISTINCTCOUNTNOBLANK(shocks[ID]), which of course is equal to 2, as such:

 

msuser48_2-1670263962182.png

 

Why is DISTINCTCOUNTNOBLANK(Shocks[ID]) not = 2 here, and how do I fix it?

 

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

Hi @msuser48 ,

This is because of the context. For your need, you need this calculate "DISTINCTCOUNTNOBLANK(Shocks[ID])" always return number 2, but for column visual, when "Years"=1, it return 1,"Years"=2,it return 2, "Years"=4,it return 1.Please refer below screenshot:

 

vbinbinyumsft_0-1670306973029.png

You just need adjust your dax formual simply, please try below dax formula:

PostCounter =
VAR _currentDeathCount =
    SELECTEDVALUE ( 'Table'[Years] )
VAR _result =
    CALCULATE (
        SUM ( 'Table'[Shock] ),
        'Table'[Years] <= _currentDeathCount,
        ALLSELECTED ( 'Table' )
    )
VAR _num =
    CALCULATE ( DISTINCTCOUNTNOBLANK ( 'Table'[ID] ), ALL ( 'Table' ) )
RETURN
    IF ( HASONEVALUE ( 'Table'[Years] ), _result, COUNTROWS ( 'Table' ) ) / _num

vbinbinyumsft_1-1670307079848.png

Please refer the attached .pbix file.

 

Best regards,
Community Support Team_Binbin Yu
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

1 REPLY 1
v-binbinyu-msft
Community Support
Community Support

Hi @msuser48 ,

This is because of the context. For your need, you need this calculate "DISTINCTCOUNTNOBLANK(Shocks[ID])" always return number 2, but for column visual, when "Years"=1, it return 1,"Years"=2,it return 2, "Years"=4,it return 1.Please refer below screenshot:

 

vbinbinyumsft_0-1670306973029.png

You just need adjust your dax formual simply, please try below dax formula:

PostCounter =
VAR _currentDeathCount =
    SELECTEDVALUE ( 'Table'[Years] )
VAR _result =
    CALCULATE (
        SUM ( 'Table'[Shock] ),
        'Table'[Years] <= _currentDeathCount,
        ALLSELECTED ( 'Table' )
    )
VAR _num =
    CALCULATE ( DISTINCTCOUNTNOBLANK ( 'Table'[ID] ), ALL ( 'Table' ) )
RETURN
    IF ( HASONEVALUE ( 'Table'[Years] ), _result, COUNTROWS ( 'Table' ) ) / _num

vbinbinyumsft_1-1670307079848.png

Please refer the attached .pbix file.

 

Best regards,
Community Support Team_Binbin Yu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

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.