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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
educrocha_agu
New Member

Filtro em outra tabela

 

modelagem do bd.png

 

Pessoal, tenho a modelagem acima.

Preciso fazer a contagem da quantidade de registros em "tb_BaseDados" e tenho a seguinte medida

 

Calculate(
count('TB_Base_Dados'[PK])
, filter('TB_Base_Dados', [DtRelatorio] >= DATEVALUE("01/05/2021"))
)
 
E funciona como esperado, fazendo a contagem dos registros de TB_BASE_DADOS.
 
Agora preciso incluir mais uma restrição tb_Conteudo[Conteudo] = 'SIM'
Calculate(
  count('TB_Base_Dados'[PK])
  , filter('TB_Base_Dados', [DtRelatorio] >= DATEVALUE("01/05/2021")
             & 'tb_Conteudo'[Conteudo] >= "SIM"
           )
 )
 

O problema é que ao inserir a segunda restrição, dá erro: "Um único valor para a coluna 'Conteudo' na tabela 'tb_Conteudo' não pode ser determinado.

 

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

Hi @educrocha_agu,

 

Not sure how you create relationships for the tables in your model. But you may try this Measure.

RecordsSIM =
VAR res =
    CALCULATE (
        COUNT ( 'tb_BaseDados'[pk] ),
        FILTER (
            'tb_BaseDados',
            'tb_BaseDados'[dtRelatorio] >= DATEVALUE ( "01/05/2021" )
                && MAX ( 'tb_Conteudo'[Conteudo] ) = "SIM"
        )
    )
RETURN
    res

 

RecordsSIM with proper total =
VAR midT =
    ADDCOLUMNS ( VALUES ( tb_BaseDados[pk] ), "val", [RecordsSIM] )
RETURN
    SUMX ( midT, [val] )

 

Then, the result looks like this.

vcazhengmsft_0-1653540890852.png

 

Also, attach the pbix as reference.

 

If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please let me know how. Thanks a lot!

 

Best Regards,

Community Support Team _ Caiyun

View solution in original post

1 REPLY 1
v-cazheng-msft
Community Support
Community Support

Hi @educrocha_agu,

 

Not sure how you create relationships for the tables in your model. But you may try this Measure.

RecordsSIM =
VAR res =
    CALCULATE (
        COUNT ( 'tb_BaseDados'[pk] ),
        FILTER (
            'tb_BaseDados',
            'tb_BaseDados'[dtRelatorio] >= DATEVALUE ( "01/05/2021" )
                && MAX ( 'tb_Conteudo'[Conteudo] ) = "SIM"
        )
    )
RETURN
    res

 

RecordsSIM with proper total =
VAR midT =
    ADDCOLUMNS ( VALUES ( tb_BaseDados[pk] ), "val", [RecordsSIM] )
RETURN
    SUMX ( midT, [val] )

 

Then, the result looks like this.

vcazhengmsft_0-1653540890852.png

 

Also, attach the pbix as reference.

 

If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please let me know how. Thanks a lot!

 

Best Regards,

Community Support Team _ Caiyun

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

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! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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

Top Solution Authors