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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric 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
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.

Top Kudoed Authors