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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
dhersz
Frequent Visitor

Question about VALUES function

Hello,

 

I'm running through a problem with the usage of VALUES function, which is exactly what this page (https://msdn.microsoft.com/en-us/library/ee634547.aspx) lists as a remark of the function: it is filtering my results, where I want it unfiltered. The page also says "To return all of the cities, regardless of existing filters, you must use the ALL function to remove filters from the table. The second example demonstrates use of ALL with VALUES.", but there is not a second example...

 

Is there any place where I could read about using the VALUES and ALL function together?

 

My code right now looks like this:

 

MédiasSemFiltro = SWITCH(VALUES('Ordem etapas'[Etapa]),
                            "EM PROSPECÇÃO", 'CRM - Acompanhamento geral'[SFMédiaProspecção],
                            "AGENDANDO VISITA", 'CRM - Acompanhamento geral'[SFMédiaAgendamento],
                            "1ª VISITA", 'CRM - Acompanhamento geral'[SFMédia1Visita],
                            "PROPOSTA", 'CRM - Acompanhamento geral'[SFMédiaProposta],
                            "2ª VISITA", 'CRM - Acompanhamento geral'[SFMédia2Visita],
                            "FECHAMENTO", 'CRM - Acompanhamento geral'[SFMédiaFechamento],
                            "CADASTROS", 'CRM - Acompanhamento geral'[SFMédiaCadastros],
                            "PROPOSTA DE COMPRA", 'CRM - Acompanhamento geral'[SFMédiaPropostaDeCompra],
                            "FECHAMENTO", 'CRM - Acompanhamento geral'[SFMédiaFechamento],
                            "CONCLUÍDO", 'CRM - Acompanhamento geral'[SFMédiaÚltimaFatura],
                            "DESCONTINUADO", 'CRM - Acompanhamento geral'[SFMédiaDescontinuamento],
                            BLANK())

I've also tried to use ALL and DISTINCT instead of VALUES, but they either return me this error "MdxScript(Model) (38, 61) A table of multiple values was supplied where a single value was expected." (in the case of ALL) or it keeps the filtered values (in the case of DISTINCT).

 

Could any of you enlighten me on this subject?

 

Best regards

1 ACCEPTED SOLUTION

@dhersz

 

If you are using a MEASURE...replace VALUES with SELECTEDVALUE

 

i.e.

 

MédiasSemFiltro =
SWITCH (
    SELECTEDVALUE ( 'Ordem etapas'[Etapa] ),
    "EM PROSPECÇÃO", 'CRM - Acompanhamento geral'[SFMédiaProspecção],
    "AGENDANDO VISITA", 'CRM - Acompanhamento geral'[SFMédiaAgendamento],
    "1ª VISITA", 'CRM - Acompanhamento geral'[SFMédia1Visita],
    "PROPOSTA", 'CRM - Acompanhamento geral'[SFMédiaProposta],
    "2ª VISITA", 'CRM - Acompanhamento geral'[SFMédia2Visita],
    "FECHAMENTO", 'CRM - Acompanhamento geral'[SFMédiaFechamento],
    "CADASTROS", 'CRM - Acompanhamento geral'[SFMédiaCadastros],
    "PROPOSTA DE COMPRA", 'CRM - Acompanhamento geral'[SFMédiaPropostaDeCompra],
    "FECHAMENTO", 'CRM - Acompanhamento geral'[SFMédiaFechamento],
    "CONCLUÍDO", 'CRM - Acompanhamento geral'[SFMédiaÚltimaFatura],
    "DESCONTINUADO", 'CRM - Acompanhamento geral'[SFMédiaDescontinuamento],
    BLANK ()
)

Regards
Zubair

Please try my custom visuals

View solution in original post

4 REPLIES 4
Zubair_Muhammad
Community Champion
Community Champion

Hi @dhersz

 

If you are using a calculated column, you should NOT use VALUES or ALL at all.

 

MédiasSemFiltro =
SWITCH (
    'Ordem etapas'[Etapa],
    "EM PROSPECÇÃO", 'CRM - Acompanhamento geral'[SFMédiaProspecção],
    "AGENDANDO VISITA", 'CRM - Acompanhamento geral'[SFMédiaAgendamento],
    "1ª VISITA", 'CRM - Acompanhamento geral'[SFMédia1Visita],
    "PROPOSTA", 'CRM - Acompanhamento geral'[SFMédiaProposta],
    "2ª VISITA", 'CRM - Acompanhamento geral'[SFMédia2Visita],
    "FECHAMENTO", 'CRM - Acompanhamento geral'[SFMédiaFechamento],
    "CADASTROS", 'CRM - Acompanhamento geral'[SFMédiaCadastros],
    "PROPOSTA DE COMPRA", 'CRM - Acompanhamento geral'[SFMédiaPropostaDeCompra],
    "FECHAMENTO", 'CRM - Acompanhamento geral'[SFMédiaFechamento],
    "CONCLUÍDO", 'CRM - Acompanhamento geral'[SFMédiaÚltimaFatura],
    "DESCONTINUADO", 'CRM - Acompanhamento geral'[SFMédiaDescontinuamento],
    BLANK ()
)

 


Regards
Zubair

Please try my custom visuals

@dhersz

 

If you are using a MEASURE...replace VALUES with SELECTEDVALUE

 

i.e.

 

MédiasSemFiltro =
SWITCH (
    SELECTEDVALUE ( 'Ordem etapas'[Etapa] ),
    "EM PROSPECÇÃO", 'CRM - Acompanhamento geral'[SFMédiaProspecção],
    "AGENDANDO VISITA", 'CRM - Acompanhamento geral'[SFMédiaAgendamento],
    "1ª VISITA", 'CRM - Acompanhamento geral'[SFMédia1Visita],
    "PROPOSTA", 'CRM - Acompanhamento geral'[SFMédiaProposta],
    "2ª VISITA", 'CRM - Acompanhamento geral'[SFMédia2Visita],
    "FECHAMENTO", 'CRM - Acompanhamento geral'[SFMédiaFechamento],
    "CADASTROS", 'CRM - Acompanhamento geral'[SFMédiaCadastros],
    "PROPOSTA DE COMPRA", 'CRM - Acompanhamento geral'[SFMédiaPropostaDeCompra],
    "FECHAMENTO", 'CRM - Acompanhamento geral'[SFMédiaFechamento],
    "CONCLUÍDO", 'CRM - Acompanhamento geral'[SFMédiaÚltimaFatura],
    "DESCONTINUADO", 'CRM - Acompanhamento geral'[SFMédiaDescontinuamento],
    BLANK ()
)

Regards
Zubair

Please try my custom visuals

That's exactly it... Thank you very much.

 

I was also calculating the measures like so:

Média1Visita = CALCULATE(AVERAGE('CRM - Acompanhamento geral'[Duração1Visita]))

So I changed to:

Média1Visita = CALCULATE(AVERAGE('CRM - Acompanhamento geral'[Duração1Visita]), ALLSELECTED('CRM - Acompanhamento geral'))

Which probably also helped Smiley LOL

@dhersz

 

You can also use VALUES function in the MEASURE.. but then you would have to take care of the total row by adding "HASONEVALUE"

 

i.e. try

 

MédiasSemFiltro =
IF (
    HASONEVALUE ( 'Ordem etapas'[Etapa] ),
    SWITCH (
        VALUES ( 'Ordem etapas'[Etapa] ),
        "EM PROSPECÇÃO", 'CRM - Acompanhamento geral'[SFMédiaProspecção],
        "AGENDANDO VISITA", 'CRM - Acompanhamento geral'[SFMédiaAgendamento],
        "1ª VISITA", 'CRM - Acompanhamento geral'[SFMédia1Visita],
        "PROPOSTA", 'CRM - Acompanhamento geral'[SFMédiaProposta],
        "2ª VISITA", 'CRM - Acompanhamento geral'[SFMédia2Visita],
        "FECHAMENTO", 'CRM - Acompanhamento geral'[SFMédiaFechamento],
        "CADASTROS", 'CRM - Acompanhamento geral'[SFMédiaCadastros],
        "PROPOSTA DE COMPRA", 'CRM - Acompanhamento geral'[SFMédiaPropostaDeCompra],
        "FECHAMENTO", 'CRM - Acompanhamento geral'[SFMédiaFechamento],
        "CONCLUÍDO", 'CRM - Acompanhamento geral'[SFMédiaÚltimaFatura],
        "DESCONTINUADO", 'CRM - Acompanhamento geral'[SFMédiaDescontinuamento],
        BLANK ()
    )
)

Regards
Zubair

Please try my custom visuals

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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.