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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

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
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

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

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

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