Reply
Syndicate_Admin
Administrator
Administrator
Syndicated - Inbound

¿Cómo hacer SUM (DISTINCT <Filed name="">) en una consulta paginada?</Filed>

Source Community: Power BI | Source Author Name: sandipghosh2

Hola

En el código en las propiedades del informe, utilizo el siguiente código:

Public Function GetDistinctSum(ByVal values As Object()) As Decimal
    distinctValues.Clear()
    For Each value In values
        If value.Rank = 4 Then
            Dim marketShare As Decimal = CDec(value.MARKET_SHARE)
            If Not distinctValues.Contains(marketShare) Then
                distinctValues.Add(marketShare)
            End If
        End If
    Next
    Dim sum As Decimal = 0
    For Each val As Decimal In distinctValues
        sum += val
    Next
    Return sum
End Function


Then I call this code as: Code.GetDistinctSum(Fields!MARKET_SHARE.Value)

I am getting below error:
There is an error on line 1 of custom code: [BC30451] 'distinctValues' is not declared. It may be inaccessible due to its protection level.
----------------------------
The definition of the report '' is invalid.
----------------------------
An error occurred during local report processing.

1 REPLY 1
Syndicate_Admin
Administrator
Administrator

Source Community: Power BI | Source Author Name: v-stephen-msft
Syndicated - Inbound

Hola @sandipghosh2 ,

Parece que el error se debe a que la variable distinctValues no se ha declarado. Debe declarar distinctValues como una colección para poder usarla en la función.

Hay una publicación similar para su referencia:

Resuelto: error: [BC30451] - informe paginado - Microsoft Fabric Community

Saludos
Esteban Tao

Si esta publicación ayuda, considere Acéptalo como la solución para ayudar a los otros miembros a encontrarlo más rápidamente

avatar user

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

Feb2025 NL Carousel

Fabric Community Update - February 2025

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

Top Solution Authors (Last Month)
Top Kudoed Authors (Last Month)