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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
jlayala
Frequent Visitor

Countries or countx returning blank total but row by row ok.

Hi everyone, hope can someone help me.

I have a table that one measure ("usuario nuevo registrados") do not gives me the total. All measures use the same table. 

 

jlayala_1-1656712316764.png    

the card show blank as total is in the table.

jlayala_2-1656712429069.png

 

 

Usuario Nuevo Registrados = 
VAR fecha =
    SELECTEDVALUE ( 'paynom usuarios'[created_at] )
VAR Fecha_min =
    EOMONTH ( fecha, -1 )
VAR Fecha_max =
    EOMONTH ( fecha, 0 )
VAR tabla_filtro =
    FILTER (
        ADDCOLUMNS (
            'paynom usuarios',
            "@Fecha_min", Fecha_min,
            "@Fecha_max", Fecha_max
        ),
        fecha > Fecha_min
            && fecha <= Fecha_max
            && 'paynom usuarios'[rol_id] = 3
            && 'paynom usuarios'[registrado] = TRUE()
    )
VAR CONTEO_USUARIOS_NUEVOS = 
    COUNTX ( 
        tabla_filtro,
        'paynom usuarios'[username] 
    )
RETURN
COUNTROWS( tabla_filtro)
the other measure is more simple 
Usuario Registrado = calculate ( 
    COUNTROWS( 'paynom usuarios') ,
        'paynom usuarios'[registrado] = TRUE() ,
        'paynom roles'[name] = "employee"
)

 

1 ACCEPTED SOLUTION
tamerj1
Super User
Super User

 Hi @jlayala 
Please try

Usuario Nuevo Registrados =
SUMX (
    TableName,
    CALCULATE (
        VAR fecha =
            SELECTEDVALUE ( 'paynom usuarios'[created_at] )
        VAR Fecha_min =
            EOMONTH ( fecha, -1 )
        VAR Fecha_max =
            EOMONTH ( fecha, 0 )
        VAR tabla_filtro =
            FILTER (
                ADDCOLUMNS (
                    'paynom usuarios',
                    "@Fecha_min", Fecha_min,
                    "@Fecha_max", Fecha_max
                ),
                fecha > Fecha_min
                    && fecha <= Fecha_max
                    && 'paynom usuarios'[rol_id] = 3
                    && 'paynom usuarios'[registrado] = TRUE ()
            )
        VAR CONTEO_USUARIOS_NUEVOS =
            COUNTX ( tabla_filtro, 'paynom usuarios'[username] )
        RETURN
            COUNTROWS ( tabla_filtro )
    )
)

View solution in original post

3 REPLIES 3
tamerj1
Super User
Super User

 Hi @jlayala 
Please try

Usuario Nuevo Registrados =
SUMX (
    TableName,
    CALCULATE (
        VAR fecha =
            SELECTEDVALUE ( 'paynom usuarios'[created_at] )
        VAR Fecha_min =
            EOMONTH ( fecha, -1 )
        VAR Fecha_max =
            EOMONTH ( fecha, 0 )
        VAR tabla_filtro =
            FILTER (
                ADDCOLUMNS (
                    'paynom usuarios',
                    "@Fecha_min", Fecha_min,
                    "@Fecha_max", Fecha_max
                ),
                fecha > Fecha_min
                    && fecha <= Fecha_max
                    && 'paynom usuarios'[rol_id] = 3
                    && 'paynom usuarios'[registrado] = TRUE ()
            )
        VAR CONTEO_USUARIOS_NUEVOS =
            COUNTX ( tabla_filtro, 'paynom usuarios'[username] )
        RETURN
            COUNTROWS ( tabla_filtro )
    )
)

It works! Thanks.  What would be the reason ? is it the aggregate function? 

Hi @jlayala 

the reason is SELECTEDVALUE which returns blank in case of multiple values found. Therefore, totals will allways be blank. SUMX restores the lost value by summing the visible values snd aggregate them in the total cell

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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